use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class ValueHelperTest method value.
@TestFactory
Stream<DynamicTest> value() {
List<TestCase> tests = new ArrayList<>();
of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MAX_VALUE), new Double(Double.MAX_VALUE));
of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MIN_VALUE), new Double(Double.MIN_VALUE));
of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MAX_VALUE), new Byte(Byte.MAX_VALUE));
of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MIN_VALUE), new Byte(Byte.MIN_VALUE));
of(tests, Schema.INT16_SCHEMA, new Short(Short.MAX_VALUE), new Short(Short.MAX_VALUE));
of(tests, Schema.INT16_SCHEMA, new Short(Short.MIN_VALUE), new Short(Short.MIN_VALUE));
of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MAX_VALUE), new Integer(Integer.MAX_VALUE));
of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MIN_VALUE), new Integer(Integer.MIN_VALUE));
of(tests, Schema.INT64_SCHEMA, new Long(Long.MAX_VALUE), new Long(Long.MAX_VALUE));
of(tests, Schema.INT64_SCHEMA, new Long(Long.MIN_VALUE), 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, new BigDecimal("12345").setScale(SCALE), new BigDecimal("12345").setScale(SCALE));
of(tests, schema, new BigDecimal("0").setScale(SCALE), new BigDecimal("0").setScale(SCALE));
of(tests, schema, new BigDecimal("-12345.001").setScale(SCALE), new BigDecimal("-12345.001").setScale(SCALE));
}
Schema structSchema = SchemaBuilder.struct().field("firstName", Schema.STRING_SCHEMA).field("lastName", Schema.STRING_SCHEMA).build();
of(tests, structSchema, ImmutableMap.of("firstName", "example", "lastName", "user"), new Struct(structSchema).put("firstName", "example").put("lastName", "user"));
of(tests, structSchema, new Struct(structSchema).put("firstName", "example").put("lastName", "user"), new Struct(structSchema).put("firstName", "example").put("lastName", "user"));
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
final Object actual = ValueHelper.value(testCase.schema, testCase.input);
assertEquals(testCase.expected, actual);
}));
}
use of org.junit.jupiter.api.TestFactory in project junit5 by junit-team.
the class ExtensionContextTests method configurationParameter.
@TestFactory
Stream<DynamicTest> configurationParameter() throws Exception {
ConfigurationParameters echo = new EchoParameters();
String key = "123";
Optional<String> expected = Optional.of(key);
UniqueId engineUniqueId = UniqueId.parse("[engine:junit-jupiter]");
JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(engineUniqueId);
UniqueId classUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(classUniqueId, getClass());
Method method = getClass().getDeclaredMethod("configurationParameter");
UniqueId methodUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]/[method:myMethod]");
TestMethodTestDescriptor methodTestDescriptor = new TestMethodTestDescriptor(methodUniqueId, getClass(), method);
return //
Stream.of(//
(ExtensionContext) new JupiterEngineExtensionContext(null, engineDescriptor, echo), //
new ClassExtensionContext(null, null, classTestDescriptor, echo, null), //
new MethodExtensionContext(null, null, methodTestDescriptor, echo, null, null)).map(context -> dynamicTest(context.getClass().getSimpleName(), () -> assertEquals(expected, context.getConfigurationParameter(key))));
}
use of org.junit.jupiter.api.TestFactory in project junit5 by junit-team.
the class ScriptTests method preconditionsAreChecked.
@TestFactory
Stream<DynamicTest> preconditionsAreChecked(TestInfo info) {
Annotation annotation = info.getTestMethod().orElseThrow(Error::new).getAnnotation(TestFactory.class);
Class<JUnitException> expected = JUnitException.class;
return //
Stream.of(//
dynamicTest("0", () -> assertNotNull(new Script(annotation, "e", "s", "r"))), //
dynamicTest("1", () -> assertThrows(expected, () -> new Script(null, "e", "s", "r"))), //
dynamicTest("2", () -> assertNotNull(new Script(Test.class, "a", "e", "s", "r"))), //
dynamicTest("3", () -> assertThrows(expected, () -> new Script(null, "a", "e", "s", "r"))), //
dynamicTest("4", () -> assertThrows(expected, () -> new Script(Test.class, null, "e", "s", "r"))), //
dynamicTest("5", () -> assertThrows(expected, () -> new Script(Test.class, "a", null, "s", "r"))), //
dynamicTest("6", () -> assertThrows(expected, () -> new Script(Test.class, "a", "e", null, "r"))), //
dynamicTest("7", () -> assertThrows(expected, () -> new Script(Test.class, "a", "e", "s", null))), //
dynamicTest("8", () -> assertNotNull(new Script(Test.class, "", "e", "s", ""))), //
dynamicTest("9", () -> assertThrows(expected, () -> new Script(Test.class, "", "", "s", ""))), //
dynamicTest("A", () -> assertThrows(expected, () -> new Script(Test.class, "", "e", "", ""))));
}
use of org.junit.jupiter.api.TestFactory in project junit5 by junit-team.
the class DynamicTestsDemo method generateRandomNumberOfTests.
@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();
// end::user_guide[]
{
// Use fixed seed to always produce the same number of tests for execution on the CI server
random = new Random(23);
}
// tag::user_guide[]
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);
}
use of org.junit.jupiter.api.TestFactory in project junit5 by junit-team.
the class ReflectionSupportTests method findAllClassesInClasspathRootDelegates.
@TestFactory
List<DynamicTest> findAllClassesInClasspathRootDelegates() throws Throwable {
List<DynamicTest> tests = new ArrayList<>();
List<Path> paths = new ArrayList<>();
paths.add(Paths.get(".").toRealPath());
paths.addAll(ReflectionUtils.getAllClasspathRootDirectories());
for (Path path : paths) {
URI root = path.toUri();
String displayName = root.getPath();
if (displayName.length() > 42) {
displayName = "..." + displayName.substring(displayName.length() - 42);
}
tests.add(DynamicTest.dynamicTest(displayName, () -> assertEquals(ReflectionUtils.findAllClassesInClasspathRoot(root, allTypes, allNames), ReflectionSupport.findAllClassesInClasspathRoot(root, allTypes, allNames))));
}
return tests;
}
Aggregations