use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class TestFactoryTestDescriptorTests method before.
@BeforeEach
void before() throws Exception {
extensionContext = mock(ExtensionContext.class);
isClosed = false;
context = new JupiterEngineExecutionContext(null, null).extend().withThrowableCollector(new ThrowableCollector()).withExtensionContext(extensionContext).build();
Method testMethod = CustomStreamTestCase.class.getDeclaredMethod("customStream");
descriptor = new TestFactoryTestDescriptor(UniqueId.forEngine("engine"), CustomStreamTestCase.class, testMethod);
when(extensionContext.getTestMethod()).thenReturn(Optional.of(testMethod));
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeAllAfterMethodsOrCallbacks.
private <T extends Extension> void invokeAllAfterMethodsOrCallbacks(JupiterEngineExecutionContext context, BiFunction<ExtensionContext, T, Executable> generator, Class<T> type) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
registry.getReversedExtensions(type).forEach(callback -> {
Executable executable = generator.apply(extensionContext, callback);
throwableCollector.execute(executable);
});
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeTestMethod.
protected void invokeTestMethod(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) {
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
throwableCollector.execute(() -> {
try {
Method testMethod = getTestMethod();
Object instance = extensionContext.getRequiredTestInstance();
executableInvoker.invoke(testMethod, instance, extensionContext, context.getExtensionRegistry());
} catch (Throwable throwable) {
invokeTestExecutionExceptionHandlers(context.getExtensionRegistry(), extensionContext, throwable);
}
});
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method prepare.
// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(context.getExtensionRegistry(), this.testClass);
// Register extensions from static fields here, at the class level but
// after extensions registered via @ExtendWith.
registerExtensionsFromFields(registry, this.testClass, null);
registerBeforeEachMethodAdapters(registry);
registerAfterEachMethodAdapters(registry);
Lifecycle lifecycle = getTestInstanceLifecycle(this.testClass, context.getConfigurationParameters());
ThrowableCollector throwableCollector = new ThrowableCollector();
ClassExtensionContext extensionContext = new ClassExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, lifecycle, context.getConfigurationParameters(), throwableCollector);
this.beforeAllMethods = findBeforeAllMethods(this.testClass, lifecycle == Lifecycle.PER_METHOD);
this.afterAllMethods = findAfterAllMethods(this.testClass, lifecycle == Lifecycle.PER_METHOD);
// @formatter:off
return context.extend().withTestInstanceProvider(testInstanceProvider(context, registry, extensionContext)).withExtensionRegistry(registry).withExtensionContext(extensionContext).withThrowableCollector(throwableCollector).build();
// @formatter:on
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method invokeBeforeAllCallbacks.
private void invokeBeforeAllCallbacks(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
for (BeforeAllCallback callback : registry.getExtensions(BeforeAllCallback.class)) {
throwableCollector.execute(() -> callback.beforeAll(extensionContext));
if (throwableCollector.isNotEmpty()) {
break;
}
}
}
Aggregations