Java 类org.junit.jupiter.api.TestFactory 实例源码

项目:mastering-junit5    文件:StreamExampleTest.java   
@TestFactory
Stream<DynamicTest> streamTest() {
    // Input data
    Integer array[] = { 1, 2, 3 };
    Iterator<Integer> inputGenerator = Arrays.asList(array).iterator();

    // Display names
    Function<Integer, String> displayNameGenerator = (
            input) -> "Data input:" + input;

    // Test executor
    ThrowingConsumer<Integer> testExecutor = (input) -> {
        System.out.println(input);
        assertTrue(input % 2 == 0);
    };

    // Returns a stream of dynamic tests
    return stream(inputGenerator, displayNameGenerator, testExecutor);
}
项目:allure-java    文件:DynamicTests.java   
@TestFactory
@Test
@Epic("epic1")
@Epic("epic2")
@Epic("epic3")
@Feature("feature1")
@Feature("feature2")
@Feature("feature3")
@Story("story1")
@Stories({
        @Story("story2"),
        @Story("story3")
})
@Owner("some-owner")
Stream<DynamicTest> dynamicTestsFromStream() {
    return Stream.of("A", "B", "C").map(str -> dynamicTest("test" + str, () -> {
    }));
}
项目:kafka-connect-cdc-mssql    文件:QueryServiceTest.java   
@TestFactory
public Stream<DynamicTest> queryTable() throws SQLException {
  List<ChangeKey> changeCaptureTables = new ArrayList<>();
  PooledConnection pooledConnection = null;
  try {
    pooledConnection = JdbcUtils.openPooledConnection(this.config, new ChangeKey(MsSqlTestConstants.DATABASE_NAME, null, null));
    MsSqlQueryBuilder queryBuilder = new MsSqlQueryBuilder(pooledConnection.getConnection());
    try (PreparedStatement statement = queryBuilder.listChangeTrackingTablesStatement()) {
      try (ResultSet resultSet = statement.executeQuery()) {
        while (resultSet.next()) {
          String databaseName = resultSet.getString("databaseName");
          String schemaName = resultSet.getString("schemaName");
          String tableName = resultSet.getString("tableName");
          ChangeKey changeKey = new ChangeKey(databaseName, schemaName, tableName);
          changeCaptureTables.add(changeKey);
          log.trace("Found Change Tracking Enabled Table {}", changeKey);
        }
      }
    }
  } finally {
    JdbcUtils.closeConnection(pooledConnection);
  }

  return changeCaptureTables.stream().map(data -> dynamicTest(data.tableName, () -> queryTable(data)));
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:StreamExampleTest.java   
@TestFactory
Stream<DynamicTest> streamTest() {
    // Input data
    Integer array[] = { 1, 2, 3 };
    Iterator<Integer> inputGenerator = Arrays.asList(array).iterator();

    // Display names
    Function<Integer, String> displayNameGenerator = (
            input) -> "Data input:" + input;

    // Test executor
    ThrowingConsumer<Integer> testExecutor = (input) -> {
        System.out.println(input);
        assertTrue(input % 2 == 0);
    };

    // Returns a stream of dynamic tests
    return stream(inputGenerator, displayNameGenerator, testExecutor);
}
项目:connect-utils    文件:AssertSchemaTest.java   
@TestFactory
public Stream<DynamicTest> assertSchema() {
  List<TestCase> tests = new ArrayList<>();
  of(tests, Schema.STRING_SCHEMA, Schema.STRING_SCHEMA, true);
  of(tests, Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, false);
  of(tests, Schema.BYTES_SCHEMA, Decimal.schema(4), false);
  of(tests, null, null, true);
  of(tests, Schema.STRING_SCHEMA, null, false);
  of(tests, null, Schema.STRING_SCHEMA, false);

  return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
    if (testCase.isEqual) {
      AssertSchema.assertSchema(testCase.expected, testCase.actual);
    } else {
      assertThrows(AssertionFailedError.class, () -> {
        AssertSchema.assertSchema(testCase.expected, testCase.actual);
      });
    }
  }));
}
项目:connect-utils    文件:JsonNodeTest.java   
@TestFactory
Stream<DynamicTest> badData() {
  List<Schema> schemas = Arrays.asList(
      Schema.INT8_SCHEMA,
      Schema.INT16_SCHEMA,
      Schema.INT32_SCHEMA,
      Schema.INT64_SCHEMA,
      Schema.FLOAT32_SCHEMA,
      Schema.FLOAT64_SCHEMA
  );

  return schemas.stream().map(schema ->
      dynamicTest(schema.type().name(), () -> {
        badDataTest(schema);
      })
  );
}
项目:connect-utils    文件:StringParserTest.java   
@TestFactory
Stream<DynamicTest> badData() {
  List<Schema> schemas = Arrays.asList(
      Schema.INT8_SCHEMA,
      Schema.INT16_SCHEMA,
      Schema.INT32_SCHEMA,
      Schema.INT64_SCHEMA,
      Schema.FLOAT32_SCHEMA,
      Schema.FLOAT64_SCHEMA
  );

  return schemas.stream().map(schema ->
      dynamicTest(schema.type().name(), () -> {
        assertThrows(DataException.class, () -> {
          parser.parseString(schema, "asdf");
        });
      })
  );
}
项目:histone-java2    文件:HttpTranslatorTest.java   
@TestFactory
@Override
public Stream<DynamicTest> loadCases(String param) throws IOException, URISyntaxException {
    return super.loadCases(param)
                .map(test -> DynamicTest.dynamicTest(test.getDisplayName(), () -> {
                    try {
                        ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
                        servletContextHandler.setContextPath("/");

                        // CXF Servlet
                        ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
                        cxfServletHolder.setInitParameter("jaxrs.serviceClasses", TestServerResource.class.getName());
                        servletContextHandler.addServlet(cxfServletHolder, "/*");


                        server = new Server(4442);
                        server.setHandler(servletContextHandler);
                        server.start();

                        Log.setLog(new StdErrLog());

                        test.getExecutable().execute();
                    } finally {
                        try {
                            server.stop();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }));
}
项目:kata-botwars    文件:EffectTest.java   
@TestFactory
@DisplayName("expires after the duration of ")
Stream<DynamicTest> statusEffectsExpireAfterDuration() {

    return IntStream.range(1, 4).mapToObj(duration ->
            dynamicTest(duration + " moves of the affected bot", () -> {
                Effect effect = createEffectFactoryFor(anyBot(),
                        duration, NoEffect.class).newInstance();
                Bot target = aBot().withStatusEffects(effect).build();

                for (int i = 0; i < duration; i++) {
                    assertFalse(effect.isExpired(), "Effect should not expire after " + i + " moves");
                    target.applyEffects();
                }
                assertTrue(effect.isExpired());
            }));

}
项目:keystore-explorer    文件:OpenSslPvkUtilTest.java   
@TestFactory
Iterable<DynamicTest> testAllPbeTypes() throws Exception {

    List<DynamicTest> tests = new ArrayList<>();

    for (PrivateKey privateKey : privateKeys()) {
        for (OpenSslPbeType pbeType : OpenSslPbeType.values()) {
            tests.add(dynamicTest("test " + pbeType.name() + "/" + privateKey.getClass().getSimpleName(), () -> {
                byte[] encKey = OpenSslPvkUtil.getEncrypted(privateKey, pbeType, PASSWORD).getBytes();
                assertEquals(privateKey, OpenSslPvkUtil.loadEncrypted(new ByteArrayInputStream(encKey), PASSWORD));
                assertEquals(ENC_OPENSSL_PVK, CryptoFileUtil.detectFileType(new ByteArrayInputStream(encKey)));
            }));
        }
    }

    return tests;
}
项目:pojo-tester    文件:FieldUtilsTest.java   
@TestFactory
Stream<DynamicTest> Should_Return_All_Permutations() throws NoSuchFieldException {
    final Field perm1A = fieldFromPermutation1Class("a");
    final Field perm1B = fieldFromPermutation1Class("b");
    final Field perm2A = fieldFromPermutation2Class("a");
    final Field perm2B = fieldFromPermutation2Class("b");
    final Field perm2C = fieldFromPermutation2Class("c");

    final TestCase testCase1 = new TestCase(Permutation1.class,
                                            newArrayList(newArrayList(perm1A),
                                                         newArrayList(perm1B),
                                                         newArrayList(perm1A, perm1B)));
    final TestCase testCase2 = new TestCase(Permutation2.class, newArrayList(newArrayList(perm2A),
                                                                             newArrayList(perm2B),
                                                                             newArrayList(perm2C),
                                                                             newArrayList(perm2A, perm2B),
                                                                             newArrayList(perm2A, perm2C),
                                                                             newArrayList(perm2B, perm2C),
                                                                             newArrayList(perm2A, perm2B, perm2C)));
    return Stream.of(testCase1, testCase2)
                 .map(value -> dynamicTest(getDefaultDisplayName(value), Should_Return_All_Permutations(value)));
}
项目:pojo-tester    文件:MethodUtilsTest.java   
@TestFactory
Stream<DynamicTest> Should_Throw_Exception_When_Setter_Was_Not_Found() throws NoSuchFieldException {
    final Field fieldA = field(Setters.class, "a");
    final Field fieldB = field(Setters.class, "b");
    final Field fieldC = field(Setters.class, "c");
    final Field fieldD = field(Setters.class, "d");
    final Field fieldF = field(Setters.class, "f");
    final Field fieldG = field(Setters.class, "g");

    return Stream.of(fieldA,
                     fieldB,
                     fieldC,
                     fieldD,
                     fieldF,
                     fieldG)
                 .map(value -> dynamicTest(getDefaultDisplayName(value),
                                           Should_Throw_Exception_When_Setter_Was_Not_Found(value)));
}
项目:pojo-tester    文件:MethodUtilsTest.java   
@TestFactory
Stream<DynamicTest> Should_Throw_Exception_When_Getter_Was_Not_Found() throws NoSuchFieldException {
    final Field fieldA = field(Getters.class, "a");
    final Field fieldB = field(Getters.class, "b");
    final Field fieldD = field(Getters.class, "d");
    final Field fieldE = field(Getters.class, "e");
    final Field fieldF = field(Getters.class, "f");
    final Field fieldG = field(Getters.class, "g");

    return Stream.of(fieldA,
                     fieldB,
                     fieldD,
                     fieldE,
                     fieldF,
                     fieldG)
                 .map(value -> dynamicTest(getDefaultDisplayName(value),
                                           Should_Throw_Exception_When_Getter_Was_Not_Found(value)));
}
项目:pojo-tester    文件:ArrayValueChangerTest.java   
@TestFactory
Stream<DynamicTest> Should_Change_Array_Value() {
    return Stream.of("a_int",
                     "a_char",
                     "a_float",
                     "a_double",
                     "a_boolean",
                     "a_byte",
                     "a_short",
                     "a_long",
                     "a_Int",
                     "a_Char",
                     "a_Float",
                     "a_Double",
                     "a_Boolean",
                     "a_Byte",
                     "a_Short",
                     "a_Long",
                     "a_object_null",
                     "a_object",
                     "a_a")
                 .map(fieldName -> dynamicTest(getDefaultDisplayName(fieldName),
                                               Should_Change_Array_Value(fieldName)));
}
项目:pojo-tester    文件:ArrayValueChangerTest.java   
@TestFactory
Stream<DynamicTest> Should_Return_True_Or_False_Whether_Can_Change_Or_Not() throws NoSuchFieldException {
    return Stream.of(new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_int"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_char"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_float"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_double"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_boolean"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_byte"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_short"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_long"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Int"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Char"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Float"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Double"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Boolean"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_Byte"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_object_null"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_object"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a_a"), true),
                     new CanChangeCase(ClassContainingArrays.class.getDeclaredField("a"), false))
                 .map(value -> dynamicTest(getDefaultDisplayName(value.field.getName()),
                                           Should_Return_True_Or_False_Whether_Can_Change_Or_Not(value)));
}
项目:pojo-tester    文件:IteratorValueChangerTest.java   
@TestFactory
Stream<DynamicTest> Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not() {
    final Collection<String> collectionABC = new ArrayList<>();
    collectionABC.add("A");
    collectionABC.add("B");
    collectionABC.add("C");

    final Collection<String> collectionAB = new ArrayList<>();
    collectionAB.add("A");
    collectionAB.add("B");

    final ArrayList<Object> emptyArrayList = new ArrayList<>();

    return Stream.of(new AreDifferentCase(null, null, false),
                     new AreDifferentCase(emptyArrayList.iterator(), emptyArrayList.iterator(), false),
                     new AreDifferentCase(collectionABC.iterator(), collectionABC.iterator(), false),
                     new AreDifferentCase(emptyArrayList.iterator(), null, true),
                     new AreDifferentCase(null, emptyArrayList.iterator(), true),
                     new AreDifferentCase(collectionAB.iterator(), collectionABC.iterator(), true))
                 .map(value -> dynamicTest(getDefaultDisplayName(value.value1 + " " + value.value2),
                                           Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not(value)));
}
项目:pojo-tester    文件:JavaTypeInstantiatorTest.java   
@TestFactory
Stream<DynamicTest> Should_Instantiate_Primitive() {
    return Stream.of(Integer.class,
                     Byte.class,
                     Character.class,
                     Double.class,
                     Float.class,
                     Integer.class,
                     Long.class,
                     Short.class,
                     boolean.class,
                     byte.class,
                     char.class,
                     double.class,
                     float.class,
                     int.class,
                     long.class,
                     short.class)
                 .map(value -> dynamicTest(getDefaultDisplayName(value), Should_Instantiate_Primitive(value)));
}
项目:pojo-tester    文件:ObjectGeneratorFastTest.java   
@TestFactory
Stream<DynamicTest> Should_Generate_Different_Objects_Recursively() {
    final ClassAndFieldPredicatePair[] pair1 = { pair(E.class), pair(F.class) };
    final ClassAndFieldPredicatePair[] pair2 = { pair(F.class) };
    final ClassAndFieldPredicatePair[] pair3 = { pair(A.class), pair(B.class), pair(F.class), pair(G.class) };

    final RecursivelyDifferentObjectTestCase case1 = new RecursivelyDifferentObjectTestCase(11,
                                                                                            pair(D.class),
                                                                                            pair1);

    final RecursivelyDifferentObjectTestCase case2 = new RecursivelyDifferentObjectTestCase(5,
                                                                                            pair(G.class),
                                                                                            pair2);

    final RecursivelyDifferentObjectTestCase case3 = new RecursivelyDifferentObjectTestCase(176,
                                                                                            pair(H.class),
                                                                                            pair3);

    return Stream.of(case1, case2, case3)
                 .map(value -> dynamicTest(getDefaultDisplayName(value),
                                           Should_Generate_Different_Objects_Recursively(value)));
}
项目:pojo-tester    文件:ObjectGeneratorTest.java   
@TestFactory
Stream<DynamicTest> Should_Generate_Different_Objects_Recursively() {
    final ClassAndFieldPredicatePair[] pair1 = { pair(E.class), pair(F.class) };
    final ClassAndFieldPredicatePair[] pair2 = { pair(F.class) };
    final ClassAndFieldPredicatePair[] pair3 = { pair(A.class), pair(B.class), pair(F.class), pair(G.class) };

    final RecursivelyDifferentObjectTestCase case1 = new RecursivelyDifferentObjectTestCase(18,
                                                                                            pair(D.class),
                                                                                            pair1);

    final RecursivelyDifferentObjectTestCase case2 = new RecursivelyDifferentObjectTestCase(6,
                                                                                            pair(G.class),
                                                                                            pair2);

    final RecursivelyDifferentObjectTestCase case3 = new RecursivelyDifferentObjectTestCase(945,
                                                                                            pair(H.class),
                                                                                            pair3);

    return Stream.of(case1, case2, case3)
                 .map(value -> dynamicTest(getDefaultDisplayName(value),
                                           Should_Generate_Different_Objects_Recursively(value)));
}
项目:pojo-tester    文件:ArrayInstantiatorTest.java   
@TestFactory
Stream<DynamicTest> Should_Create_Array_By_Class() {
    return Stream.of(Integer[].class,
                     Byte[].class,
                     Character[].class,
                     Double[].class,
                     Float[].class,
                     Integer[].class,
                     Long[].class,
                     Short[].class,
                     boolean[].class,
                     byte[].class,
                     char[].class,
                     double[].class,
                     float[].class,
                     int[].class,
                     long[].class,
                     short[].class)
                 .map(value -> dynamicTest(getDefaultDisplayName(value), Should_Create_Array(value)));
}
项目:semantic-version    文件:ParsingTest.java   
@TestFactory
Collection<DynamicTest> testParseWithException() {
    final List<DynamicTest> results = new ArrayList<>(
            ILLEGAL_VERSIONS.length);

    for (final String[] input : ILLEGAL_VERSIONS) {
        results.add(dynamicTest("Parse " + input[0],
                () -> {
                    final VersionFormatException e = expectThrows(
                            VersionFormatException.class,
                            () -> Version.parseVersion(input[0]));

                    final String expectedMessage = String.format(input[1], input[0]);
                    assertEquals(expectedMessage, e.getMessage());
                }));
    }

    return results;
}
项目:semantic-version    文件:ParsingTest.java   
@TestFactory
Collection<DynamicTest> testWithPreReleaseException() {
    final List<DynamicTest> results = new ArrayList<>(
            ILLEGAL_PRE_RELEASES.length);

    for (final String input : ILLEGAL_PRE_RELEASES) {
        results.add(dynamicTest("Pre release " + input,
                () -> {
                    expectThrows(VersionFormatException.class,
                            () -> Version.create(1, 2, 3).withPreRelease(input));

                }));
    }

    return results;
}
项目:kafka-connect-transform-cef    文件:CEFTransformationTest.java   
@TestFactory
public Stream<DynamicTest> apply() throws IOException {
  List<TestCase> testCases = TestDataUtils.loadJsonResourceFiles(this.getClass().getPackage().getName() + ".records", TestCase.class);

  return testCases.stream().map(testCase -> dynamicTest(testCase.testName(), () -> {
    ConnectRecord actual = this.transformation.apply(testCase.input);
    assertRecord(testCase.expected, actual);
  }));
}
项目:mastering-junit5    文件:CollectionTest.java   
@TestFactory
Iterator<DynamicTest> dynamicTestsFromIterator() {
    return Arrays.asList(
            dynamicTest("5th dynamic test", () -> assertTrue(true)),
            dynamicTest("6th dynamic test", () -> assertEquals(4, 2 * 2)))
            .iterator();
}
项目:mastering-junit5    文件:DynamicExampleTest.java   
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() {
    Stream<String> inputStream = Stream.of("A", "B", "C");
    return inputStream.map(
            input -> dynamicTest("Display name for input " + input, () -> {
                System.out.println("Testing " + input);
            }));
}
项目:mastering-junit5    文件:TestInterfaceDynamicTestsDemo.java   
@TestFactory
default Collection<DynamicTest> dynamicTestsFromCollection() {
    return Arrays.asList(
            dynamicTest("1st dynamic test in test interface",
                    () -> assertTrue(true)),
            dynamicTest("2nd dynamic test in test interface",
                    () -> assertTrue(true)));
}
项目:codingdojoleipzig    文件:WrapperTest.java   
/**
 * Read the rules and generate a dynamic test at runtime for each read rule line.
 *
 * @return A {@link Stream} of {@link DynamicTest} objects corresponding to the contents of the test rule file.
 */
@TestFactory
public Stream<DynamicTest> generateTests() {
    Stream<ParsedTestRule> parsedRules = TestRuleParser.parseRuleFile(TEST_RULES_RESOURCE_NAME);
    Stream<DynamicTest> result = parsedRules.map(rule -> {
        String testName = constructTestNameForRule(rule);
        Executable testCase = constructTestCaseForRule(rule);
        return DynamicTest.dynamicTest(testName, testCase);
    });

    return result;
}
项目:kafka-connect-rabbitmq    文件:MessageConverterTest.java   
@TestFactory
public Stream<DynamicTest> headers() {
  final List<HeaderTestCase> tests = Arrays.asList(
      HeaderTestCase.of(Byte.valueOf("1"), Schema.Type.INT8.toString().toLowerCase(), Byte.valueOf("1")),
      HeaderTestCase.of(Short.valueOf("1"), Schema.Type.INT16.toString().toLowerCase(), Short.valueOf("1")),
      HeaderTestCase.of(Integer.valueOf("1"), Schema.Type.INT32.toString().toLowerCase(), Integer.valueOf("1")),
      HeaderTestCase.of(Long.valueOf("1"), Schema.Type.INT64.toString().toLowerCase(), Long.valueOf("1")),
      HeaderTestCase.of(Float.valueOf("1"), Schema.Type.FLOAT32.toString().toLowerCase(), Float.valueOf("1")),
      HeaderTestCase.of(Double.valueOf("1"), Schema.Type.FLOAT64.toString().toLowerCase(), Double.valueOf("1")),
      HeaderTestCase.of("1", Schema.Type.STRING.toString().toLowerCase(), "1"),
      HeaderTestCase.of(LongStringHelper.asLongString("1"), Schema.Type.STRING.toString().toLowerCase(), "1"),
      HeaderTestCase.of(new Date(1500691965123L), "timestamp", new Date(1500691965123L))
  );

  return tests.stream().map(test -> dynamicTest(test.toString(), () -> {
    final Map<String, Object> INPUT_HEADERS = ImmutableMap.of("input", test.input);
    BasicProperties basicProperties = mock(BasicProperties.class);
    when(basicProperties.getHeaders()).thenReturn(INPUT_HEADERS);
    final Map<String, Struct> actual = MessageConverter.headers(basicProperties);
    verify(basicProperties, only()).getHeaders();
    assertNotNull(actual, "actual should not be null.");
    assertTrue(actual.containsKey("input"), "actual should contain key 'input'");
    Struct actualStruct = actual.get("input");
    actualStruct.validate();
    assertStruct(test.expectedStruct(), actualStruct);
  }));
}
项目:kafka-connect-rabbitmq    文件:ExtractHeaderTest.java   
@TestFactory
public Stream<DynamicTest> apply() throws IOException {
  return TestDataUtils.loadJsonResourceFiles(this.getClass().getPackage().getName() + ".extractheader", TestCase.class)
      .stream()
      .map(t -> dynamicTest(t.testName(), () -> {
        final boolean isKey = t.testName().startsWith("key");
        final Transformation<SourceRecord> transformation = isKey ? new ExtractHeader.Key() : new ExtractHeader.Value();
        transformation.configure(
            ImmutableMap.of(ExtractHeaderConfig.HEADER_NAME_CONF, "foo")
        );
        final SourceRecord actual = transformation.apply(t.input);
        assertRecord(t.expected, actual);
      }));
}
项目:catalysts_coding_contest_template    文件:Level.java   
@TestFactory
default Stream<DynamicTest> files() {

    final Level instance = createLevelInstance();
    final LevelTestFactory factory = new LevelTestFactory(instance);

    try {
        return factory.create();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:shuffleboard    文件:UtilityClassTest.java   
@TestFactory
public Stream<DynamicTest> constructorsReflectionDynamicTests() {
  return DynamicTest.stream(Arrays.asList(clazz.getDeclaredConstructors()).iterator(), Constructor::getName,
      constructor -> assertThrows(InvocationTargetException.class, () -> {
        constructor.setAccessible(true);
        constructor.newInstance();
      }, String.format("The Utility class %s has a non-private constructor.", clazz.getName())));
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:CollectionTest.java   
@TestFactory
Iterator<DynamicTest> dynamicTestsFromIterator() {
    return Arrays.asList(
            dynamicTest("5th dynamic test", () -> assertTrue(true)),
            dynamicTest("6th dynamic test", () -> assertEquals(4, 2 * 2)))
            .iterator();
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:DynamicExampleTest.java   
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() {
    Stream<String> inputStream = Stream.of("A", "B", "C");
    return inputStream.map(
            input -> dynamicTest("Display name for input " + input, () -> {
                System.out.println("Testing " + input);
            }));
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:TestInterfaceDynamicTestsDemo.java   
@TestFactory
default Collection<DynamicTest> dynamicTestsFromCollection() {
    return Arrays.asList(
            dynamicTest("1st dynamic test in test interface",
                    () -> assertTrue(true)),
            dynamicTest("2nd dynamic test in test interface",
                    () -> assertTrue(true)));
}
项目:roboslack    文件:ColorTests.java   
@TestFactory
Stream<DynamicTest> testNoArgStaticFactories() {
    return DynamicTest.stream(
            MoreReflection.findNoArgStaticFactories(Color.class).iterator(),
            Object::toString,
            MoreReflection.noArgStaticFactoryConsumer(ColorTests::assertValid));
}
项目:kafka-connect-cdc-oracle    文件:JsonDatumTests.java   
@TestFactory
public Stream<DynamicTest> roundtrip() throws IOException, SQLException {
  List<Datum> testCases = Arrays.asList(
      new NUMBER(BigDecimal.valueOf(314, 2)),
      new CHAR("This is a test value", CharacterSet.make(CharacterSet.DEFAULT_CHARSET)),
      new BINARY_DOUBLE(3.14D),
      new BINARY_FLOAT(3.14F)
  );

  return testCases.stream().map(testcase -> dynamicTest(testcase.getClass().getSimpleName(), () -> assertDatum(testcase)));
}
项目:rest-yaml-test    文件:MainTest.java   
@TestFactory
public Stream<DynamicTest> tests() throws Exception {

    Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();

    for (YamlTestGroup yamlTestGroup : yamlTestGroups) {
        if (!yamlTestGroup.isTagged()) {
            logger.info("->testGroup skipped tag does not exist for testGroup name=" 
                        + yamlTestGroup.getName()+", tags="+yamlTestGroup.getTags());
            continue;
        }

        for (YamlTest yamlTest : yamlTestGroup.getTests()) {
            final String testcaseName = "testGroup=" + yamlTestGroup.getName()
                                        + ", test=" + yamlTest.getName()
                                        + ", group tags="+yamlTestGroup.getTags()
                                        + ", test tags="+yamlTest.getTags();
            if (!yamlTest.isTagged()) {
                logger.info("->test skipped tag does not exist " + testcaseName);
                continue;
            }


            Executable executable = setupTest(yamlTestGroup, yamlTest, testcaseName);
            DynamicTest dTest = DynamicTest.dynamicTest(testcaseName, executable);
            dynamicTests.add(dTest);

        }
    }

    return dynamicTests.stream();
}
项目:connect-utils    文件:StringParserTest.java   
@TestFactory
Stream<DynamicTest> parseString() {
  List<TestCase> tests = new ArrayList<>();
  of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MAX_VALUE).toString(), new Double(Double.MAX_VALUE));
  of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MIN_VALUE).toString(), new Double(Double.MIN_VALUE));

  of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MAX_VALUE).toString(), new Byte(Byte.MAX_VALUE));
  of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MIN_VALUE).toString(), new Byte(Byte.MIN_VALUE));

  of(tests, Schema.INT16_SCHEMA, new Short(Short.MAX_VALUE).toString(), new Short(Short.MAX_VALUE));
  of(tests, Schema.INT16_SCHEMA, new Short(Short.MIN_VALUE).toString(), new Short(Short.MIN_VALUE));

  of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MAX_VALUE).toString(), new Integer(Integer.MAX_VALUE));
  of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MIN_VALUE).toString(), new Integer(Integer.MIN_VALUE));

  of(tests, Schema.INT64_SCHEMA, new Long(Long.MAX_VALUE).toString(), new Long(Long.MAX_VALUE));
  of(tests, Schema.INT64_SCHEMA, new Long(Long.MIN_VALUE).toString(), new Long(Long.MIN_VALUE));

  of(tests, Schema.STRING_SCHEMA, "", "");
  of(tests, Schema.STRING_SCHEMA, "mirror", "mirror");

  for (int SCALE = 3; SCALE < 30; SCALE++) {
    Schema schema = Decimal.schema(SCALE);
    of(tests, schema, "12345", new BigDecimal("12345").setScale(SCALE));
    of(tests, schema, "0", new BigDecimal("0").setScale(SCALE));
    of(tests, schema, "-12345.001", new BigDecimal("-12345.001").setScale(SCALE));
  }

  return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
    final Object actual = parser.parseString(testCase.schema, testCase.input);
    assertEquals(testCase.expected, actual);
  }));
}
项目:connect-utils    文件:ValidHostAndPortTest.java   
@TestFactory
public Stream<DynamicTest> invalid() {
  return Arrays.asList(
      (Object) Byte.MAX_VALUE,
      (Object) true,
      (Object) Integer.MAX_VALUE,
      (Object) Short.MAX_VALUE
  ).stream().map(input -> dynamicTest(input.getClass().getSimpleName(), () -> {
    assertThrows(ConfigException.class, () -> {
      ValidHostAndPort.of().ensureValid("foo", input);
    });
  }));
}
项目:connect-utils    文件:ValidHostAndPortTest.java   
@TestFactory
public Stream<DynamicTest> invalidString() {
  return Arrays.asList(
      null,
      "127.0.0.1",
      "::1:9021",
      ":9021"
  ).stream().map(input -> dynamicTest(Strings.isNullOrEmpty(input) ? "null" : input, () -> {
    assertThrows(ConfigException.class, () -> {
      ValidHostAndPort.of().ensureValid("foo", input);
    });
  }));
}