use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class ParameterizedTestExtensionTests method supportsReturnsFalseForMissingTestMethod.
@Test
void supportsReturnsFalseForMissingTestMethod() {
ExtensionContext extensionContextWithoutTestMethod = getExtensionContextReturningSingleMethod(new TestCaseWithoutMethod());
assertFalse(this.parameterizedTestExtension.supportsTestTemplate(extensionContextWithoutTestMethod));
}
use of org.junit.jupiter.api.extension.ExtensionContext 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.ExtensionContext 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.ExtensionContext in project junit5 by junit-team.
the class CsvFileArgumentsProviderTests method provide.
private Stream<Object[]> provide(CsvFileArgumentsProvider provider, CsvFileSource annotation) {
provider.accept(annotation);
ExtensionContext context = mock(ExtensionContext.class);
when(context.getTestClass()).thenReturn(Optional.of(CsvFileArgumentsProviderTests.class));
doCallRealMethod().when(context).getRequiredTestClass();
return provider.provideArguments(context).map(Arguments::get);
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class MethodArgumentsProviderTests method provideArguments.
private Stream<Object[]> provideArguments(Class<?> testClass, Method testMethod, boolean allowNonStaticMethod, String... methodNames) {
MethodSource annotation = mock(MethodSource.class);
when(annotation.value()).thenReturn(methodNames);
ExtensionContext context = mock(ExtensionContext.class);
when(context.getTestClass()).thenReturn(Optional.ofNullable(testClass));
when(context.getTestMethod()).thenReturn(Optional.ofNullable(testMethod));
doCallRealMethod().when(context).getRequiredTestMethod();
doCallRealMethod().when(context).getRequiredTestClass();
Object testInstance = allowNonStaticMethod ? ReflectionUtils.newInstance(testClass) : null;
when(context.getTestInstance()).thenReturn(Optional.ofNullable(testInstance));
MethodArgumentsProvider provider = new MethodArgumentsProvider();
provider.accept(annotation);
return provider.provideArguments(context).map(Arguments::get);
}
Aggregations