Java Code Examples for org.junit.jupiter.api.DynamicTest#stream()

The following examples show how to use org.junit.jupiter.api.DynamicTest#stream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicTestsUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() {

    // sample input and output
    List<String> inputList = Arrays.asList("www.somedomain.com", "www.anotherdomain.com", "www.yetanotherdomain.com");
    List<String> outputList = Arrays.asList("154.174.10.56", "211.152.104.132", "178.144.120.156");

    // input generator that generates inputs using inputList
    Iterator<String> inputGenerator = inputList.iterator();

    // a display name generator that creates a different name based on the input
    Function<String, String> displayNameGenerator = (input) -> "Resolving: " + input;

    // the test executor, which actually has the logic of how to execute the test case
    DomainNameResolver resolver = new DomainNameResolver();
    ThrowingConsumer<String> testExecutor = (input) -> {
        int id = inputList.indexOf(input);
        assertEquals(outputList.get(id), resolver.resolveDomain(input));
    };

    // combine everything and return a Stream of DynamicTest
    return DynamicTest.stream(inputGenerator, displayNameGenerator, testExecutor);
}
 
Example 2
Source File: ArchitectureTest.java    From taskana with Apache License 2.0 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> classesShouldNotDependOnMonitorDomainClasses() {
  Stream<String> packagesToTest =
      TASKANA_SUB_PACKAGES.stream()
          .map(p -> p.split("\\.")[2])
          .distinct()
          .filter(d -> !"monitor".equals(d))
          .map(d -> ".." + d + "..");

  ThrowingConsumer<String> testMethod =
      p ->
          noClasses()
              .that()
              .resideInAPackage(p)
              .and()
              .haveNameNotMatching(".*TaskanaEngine.*")
              .should()
              .dependOnClassesThat()
              .resideInAnyPackage("..monitor..")
              .check(importedClasses);
  return DynamicTest.stream(
      packagesToTest.iterator(),
      p -> String.format("Domain %s should not depend on monitor", p),
      testMethod);
}
 
Example 3
Source File: ArchitectureTest.java    From taskana with Apache License 2.0 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> commonClassesShouldNotDependOnOtherDomainClasses() {
  Stream<String> packagesToTest =
      TASKANA_SUB_PACKAGES.stream()
          .map(p -> p.split("\\.")[2])
          .distinct()
          .filter(d -> !"common".equals(d))
          .map(d -> ".." + d + "..");
  ThrowingConsumer<String> testMethod =
      p ->
          noClasses()
              .that()
              .haveNameNotMatching(".*TaskanaEngine.*")
              .and()
              .haveSimpleNameNotEndingWith("AbstractTaskanaJob")
              .and()
              .resideInAPackage("..common..")
              .should()
              .dependOnClassesThat()
              .resideInAPackage(p)
              .check(importedClasses);
  return DynamicTest.stream(
      packagesToTest.iterator(), p -> p + " should not be used by common", testMethod);
}
 
Example 4
Source File: ArchitectureTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> everySubPackageShouldBeFreeOfCyclicDependencies() {
  Stream<String> packagesToTest = TASKANA_SUB_PACKAGES.stream().map(s -> s + ".(*)..");
  ThrowingConsumer<String> testMethod =
      p -> slices().matching(p).should().beFreeOfCycles().check(importedClasses);
  return DynamicTest.stream(
      packagesToTest.iterator(),
      p -> p.replaceAll(Pattern.quote("pro.taskana."), "") + " is free of cycles",
      testMethod);
}
 
Example 5
Source File: DynamicTests.java    From tutorials with MIT License 5 votes vote down vote up
@TestFactory
public Stream<DynamicTest> dynamicUserTestCollection() {
    List<User> inputList = Arrays.asList(new User("[email protected]", "John"), new User("[email protected]", "Ana"));

    Function<User, String> displayNameGenerator = (input) -> "Saving user: " + input;

    UserDAO userDAO = new UserDAO();
    ThrowingConsumer<User> testExecutor = (input) -> {
        userDAO.add(input);
        assertNotNull(userDAO.findOne(input.getEmail()));
    };

    return DynamicTest.stream(inputList.iterator(), displayNameGenerator, testExecutor);
}
 
Example 6
Source File: PlatformTests.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> javaExecutableNamesAreNotBlank() {
  return DynamicTest.stream(
      Arrays.asList(Platform.values()).iterator(),
      Object::toString,
      platform -> {
        assertNotNull(platform.javaExecutableName());
        assertFalse(platform.javaExecutableName().isEmpty());
      }
  );
}
 
Example 7
Source File: ColorTests.java    From roboslack with Apache License 2.0 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> testNoArgStaticFactories() {
    return DynamicTest.stream(
            MoreReflection.findNoArgStaticFactories(Color.class).iterator(),
            Object::toString,
            MoreReflection.noArgStaticFactoryConsumer(ColorTests::assertValid));
}
 
Example 8
Source File: ArchitecturallyEvidentTypeUnitTest.java    From moduliths with Apache License 2.0 5 votes vote down vote up
@TestFactory // #104
Stream<DynamicTest> considersJDddEntity() {

	return DynamicTest.stream(getTypesFor(JDddAnnotatedEntity.class, JDddImplementingEntity.class), //
			it -> String.format("%s is considered an entity", it.getType().getSimpleName()), //
			it -> {
				assertThat(it.isEntity()).isTrue();
				assertThat(it.isAggregateRoot()).isFalse();
				assertThat(it.isRepository()).isFalse();
			});
}
 
Example 9
Source File: ArchitectureTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> everyPackageWhichIsTestedForCyclicDependenciesShouldExist() {
  return DynamicTest.stream(
      TASKANA_SUB_PACKAGES.iterator(),
      p -> String.format("package '%s' exists", p),
      p -> assertThat(importedClasses.containPackage(p)).isTrue());
}
 
Example 10
Source File: QueryTasksAccTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> testQueryForOrderByCustomXDesc() {
  Iterator<String> iterator = IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).iterator();

  return DynamicTest.stream(
      iterator,
      s -> String.format("order by custom%s desc", s),
      s -> testQueryForOrderByCustomX(s, DESCENDING));
}
 
Example 11
Source File: QueryTasksAccTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> testQueryForOrderByCustomXAsc() {
  Iterator<String> iterator = IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).iterator();
  return DynamicTest.stream(
      iterator,
      s -> String.format("order by custom%s asc", s),
      s -> testQueryForOrderByCustomX(s, ASCENDING));
}
 
Example 12
Source File: QueryTasksAccTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> testQueryForCustomX() {
  List<Triplet<String, String[], Integer>> list =
      Arrays.asList(
          new Triplet<>("1", new String[] {"custom%", "p%", "%xyz%", "efg"}, 3),
          new Triplet<>("2", new String[] {"custom%", "a%"}, 2),
          new Triplet<>("3", new String[] {"ffg"}, 1),
          new Triplet<>("4", new String[] {"%ust%", "%ty"}, 2),
          new Triplet<>("5", new String[] {"ew", "al"}, 6),
          new Triplet<>("6", new String[] {"%custom6%", "%vvg%", "11%"}, 5),
          new Triplet<>("7", new String[] {"%"}, 2),
          new Triplet<>("8", new String[] {"%"}, 2),
          new Triplet<>("9", new String[] {"%"}, 2),
          new Triplet<>("10", new String[] {"%"}, 3),
          new Triplet<>("11", new String[] {"%"}, 3),
          new Triplet<>("12", new String[] {"%"}, 3),
          new Triplet<>("13", new String[] {"%"}, 3),
          new Triplet<>("14", new String[] {"%"}, 84),
          new Triplet<>("15", new String[] {"%"}, 3),
          new Triplet<>("16", new String[] {"%"}, 3));

  return DynamicTest.stream(
      list.iterator(),
      t -> ("custom" + t.getLeft()),
      t -> testQueryForCustomX(t.getLeft(), t.getMiddle(), t.getRight()));
}
 
Example 13
Source File: DynamicTests.java    From javatech with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> generateRandomNumberOfTests() {

    // Generates random positive integers between 0 and 100 until
    // a number evenly divisible by 7 is encountered.
    Iterator<Integer> inputGenerator = new Iterator<Integer>() {

        Random random = new Random();

        int current;

        @Override
        public boolean hasNext() {
            current = random.nextInt(100);
            return current % 7 != 0;
        }

        @Override
        public Integer next() {
            return current;
        }
    };

    // Generates display names like: input:5, input:37, input:85, etc.
    Function<Integer, String> displayNameGenerator = (input) -> "input:" + input;

    // Executes tests based on the current input value.
    ThrowingConsumer<Integer> testExecutor = (input) -> assertTrue(input % 7 != 0);

    // Returns a stream of dynamic tests.
    return DynamicTest.stream(inputGenerator, displayNameGenerator, testExecutor);
}
 
Example 14
Source File: ArchitecturallyEvidentTypeUnitTest.java    From moduliths with Apache License 2.0 5 votes vote down vote up
@TestFactory // #104
Stream<DynamicTest> considersJDddRepository() {

	return DynamicTest.stream(getTypesFor(JDddAnnotatedRepository.class), //
			it -> String.format("%s is considered a repository", it.getType().getSimpleName()), //
			it -> {
				assertThat(it.isEntity()).isFalse();
				assertThat(it.isAggregateRoot()).isFalse();
				assertThat(it.isRepository()).isTrue();
			});
}
 
Example 15
Source File: ArchitecturallyEvidentTypeUnitTest.java    From moduliths with Apache License 2.0 5 votes vote down vote up
@TestFactory // #104
Stream<DynamicTest> considersJDddAggregateRoot() {

	return DynamicTest.stream(getTypesFor(JDddAnnotatedAggregateRoot.class, JDddImplementingAggregateRoot.class), //
			it -> String.format("%s is considered an aggregate root", it.getType().getSimpleName()), //
			it -> {
				assertThat(it.isEntity()).isTrue();
				assertThat(it.isAggregateRoot()).isTrue();
				assertThat(it.isRepository()).isFalse();
			});
}
 
Example 16
Source File: SlackMarkdownTests.java    From roboslack with Apache License 2.0 4 votes vote down vote up
@TestFactory
Stream<DynamicTest> testStringDecorators() {
    return DynamicTest.stream(fieldValuesOfDecoratorString(SlackMarkdown.class).iterator(),
            Object::toString,
            stringDecoratorConsumer(EXAMPLE_INPUT));
}
 
Example 17
Source File: SlackMarkdownTests.java    From roboslack with Apache License 2.0 4 votes vote down vote up
@TestFactory
Stream<DynamicTest> testLinkDecorators() {
    return DynamicTest.stream(fieldValuesOfTupleDecoratorUrlString(SlackMarkdown.class).iterator(),
            Object::toString,
            tupleUrlStringDecoratorConsumer(EXAMPLE_URL, EXAMPLE_INPUT));
}