@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); }
private static ThrowingConsumer<ValueDecorator<String>> stringDecoratorConsumer(String input) { return decorator -> { String expectedDecorated = decorator.prefix().orElse("") + input + decorator.suffix().orElse(""); assertThat(decorator.decorate(input), is(equalTo(expectedDecorated))); assertThat(decorator.decorate(expectedDecorated), is(equalTo(expectedDecorated))); }; }
private static ThrowingConsumer<TupleDecorator<URL, String>> tupleUrlStringDecoratorConsumer(URL inputUrl, String inputText) { return decorator -> { String expectedDecorated = decorator.prefix().orElse("") + inputUrl.toString() + decorator.separator() + inputText + decorator.suffix().orElse(""); assertThat(decorator.decorate(inputUrl, inputText), is(equalTo(expectedDecorated))); }; }
@SuppressWarnings("unchecked") public static <T> ThrowingConsumer<Method> noArgStaticFactoryConsumer(Consumer<T> delegateConsumer) { return staticFactoryMethod -> delegateConsumer.accept((T) staticFactoryMethod.invoke(null)); }