use of org.junit.jupiter.api.extension.ExtensionContext 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.api.extension.ExtensionContext in project junit5 by junit-team.
the class TestTemplateTestDescriptor method execute.
@Override
public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) throws Exception {
ExtensionContext extensionContext = context.getExtensionContext();
List<TestTemplateInvocationContextProvider> providers = validateProviders(extensionContext, context.getExtensionRegistry());
AtomicInteger invocationIndex = new AtomicInteger();
// @formatter:off
providers.stream().flatMap(provider -> provider.provideTestTemplateInvocationContexts(extensionContext)).map(invocationContext -> createInvocationTestDescriptor(invocationContext, invocationIndex.incrementAndGet())).filter(Optional::isPresent).map(Optional::get).forEach(invocationTestDescriptor -> execute(dynamicTestExecutor, invocationTestDescriptor));
// @formatter:on
validateWasAtLeastInvokedOnce(invocationIndex.get());
return context;
}
use of org.junit.jupiter.api.extension.ExtensionContext 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;
}
}
}
use of org.junit.jupiter.api.extension.ExtensionContext 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.api.extension.ExtensionContext 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)));
}
Aggregations