use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method before.
@Override
public JupiterEngineExecutionContext before(JupiterEngineExecutionContext context) throws Exception {
Lifecycle lifecycle = context.getExtensionContext().getTestInstanceLifecycle().orElse(Lifecycle.PER_METHOD);
if (lifecycle == Lifecycle.PER_CLASS) {
// Eagerly load test instance for BeforeAllCallbacks, if necessary,
// and store the instance in the ExtensionContext.
ClassExtensionContext extensionContext = (ClassExtensionContext) context.getExtensionContext();
extensionContext.setTestInstance(context.getTestInstanceProvider().getTestInstance(Optional.empty()));
}
ThrowableCollector throwableCollector = context.getThrowableCollector();
invokeBeforeAllCallbacks(context);
if (throwableCollector.isEmpty()) {
context.beforeAllMethodsExecuted(true);
invokeBeforeAllMethods(context);
}
throwableCollector.assertEmpty();
return context;
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method invokeAfterAllMethods.
private void invokeAfterAllMethods(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
Object testInstance = extensionContext.getTestInstance().orElse(null);
this.afterAllMethods.forEach(method -> throwableCollector.execute(() -> executableInvoker.invoke(method, testInstance, extensionContext, registry)));
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method invokeAfterAllCallbacks.
private void invokeAfterAllCallbacks(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
//
registry.getReversedExtensions(AfterAllCallback.class).forEach(extension -> throwableCollector.execute(() -> extension.afterAll(extensionContext)));
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class ClassTestDescriptor method invokeBeforeAllMethods.
private void invokeBeforeAllMethods(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
Object testInstance = extensionContext.getTestInstance().orElse(null);
for (Method method : this.beforeAllMethods) {
throwableCollector.execute(() -> executableInvoker.invoke(method, testInstance, extensionContext, registry));
if (throwableCollector.isNotEmpty()) {
break;
}
}
}
use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.
the class TestMethodTestDescriptor method prepare.
// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) throws Exception {
ExtensionRegistry registry = populateNewExtensionRegistry(context);
Object testInstance = context.getTestInstanceProvider().getTestInstance(Optional.of(registry));
ThrowableCollector throwableCollector = new ThrowableCollector();
ExtensionContext extensionContext = new MethodExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, context.getConfigurationParameters(), testInstance, throwableCollector);
// @formatter:off
return context.extend().withExtensionRegistry(registry).withExtensionContext(extensionContext).withThrowableCollector(throwableCollector).build();
// @formatter:on
}
Aggregations