use of org.junit.jupiter.api.extension.TestTemplateInvocationContext in project junit5 by junit-team.
the class ParameterizedTestExtensionTests method streamsReturnedByProvidersAreClosedWhenCallingProvide.
@Test
void streamsReturnedByProvidersAreClosedWhenCallingProvide() {
ExtensionContext extensionContext = getExtensionContextReturningSingleMethod(new TestCaseWithArgumentSourceAnnotatedMethod());
Stream<TestTemplateInvocationContext> stream = this.parameterizedTestExtension.provideTestTemplateInvocationContexts(extensionContext);
// cause the stream to be evaluated
stream.count();
assertTrue(streamWasClosed);
}
use of org.junit.jupiter.api.extension.TestTemplateInvocationContext in project junit5 by junit-team.
the class ParameterizedTestExtensionTests method throwsExceptionWhenParameterizedTestIsNotInvokedAtLeastOnce.
@Test
void throwsExceptionWhenParameterizedTestIsNotInvokedAtLeastOnce() {
ExtensionContext extensionContextWithAnnotatedTestMethod = getExtensionContextReturningSingleMethod(new TestCaseWithAnnotatedMethod());
Stream<TestTemplateInvocationContext> stream = this.parameterizedTestExtension.provideTestTemplateInvocationContexts(extensionContextWithAnnotatedTestMethod);
// cause the stream to be evaluated
stream.toArray();
JUnitException exception = assertThrows(JUnitException.class, stream::close);
assertThat(exception).hasMessage("Configuration error: You must provide at least one argument for this @ParameterizedTest");
}
use of org.junit.jupiter.api.extension.TestTemplateInvocationContext in project junit5 by junit-team.
the class ParameterizedTestExtension method provideTestTemplateInvocationContexts.
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
Method templateMethod = context.getRequiredTestMethod();
ParameterizedTestNameFormatter formatter = createNameFormatter(templateMethod);
AtomicLong invocationCount = new AtomicLong(0);
// @formatter:off
return findRepeatableAnnotations(templateMethod, ArgumentsSource.class).stream().map(ArgumentsSource::value).map(ReflectionUtils::newInstance).map(provider -> AnnotationConsumerInitializer.initialize(templateMethod, provider)).flatMap(provider -> arguments(provider, context)).map(Arguments::get).map(arguments -> consumedArguments(arguments, templateMethod)).map(arguments -> createInvocationContext(formatter, arguments)).peek(invocationContext -> invocationCount.incrementAndGet()).onClose(() -> Preconditions.condition(invocationCount.get() > 0, () -> "Configuration error: You must provide at least one argument for this @" + ParameterizedTest.class.getSimpleName()));
// @formatter:on
}
Aggregations