use of org.junit.jupiter.engine.extension.ExtensionRegistry 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
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeBeforeMethodsOrCallbacksUntilExceptionOccurs.
private <T extends Extension> void invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(JupiterEngineExecutionContext context, BiFunction<ExtensionContext, T, Executable> generator, Class<T> type) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
for (T callback : registry.getExtensions(type)) {
Executable executable = generator.apply(extensionContext, callback);
throwableCollector.execute(executable);
if (throwableCollector.isNotEmpty()) {
break;
}
}
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeAfterEachMethods.
private void invokeAfterEachMethods(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
invokeAllAfterMethodsOrCallbacks(context, ((extensionContext, adapter) -> () -> adapter.invokeAfterEachMethod(extensionContext, registry)), AfterEachMethodAdapter.class);
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeBeforeEachMethods.
private void invokeBeforeEachMethods(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = context.getExtensionRegistry();
invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(context, ((extensionContext, adapter) -> () -> adapter.invokeBeforeEachMethod(extensionContext, registry)), BeforeEachMethodAdapter.class);
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class TestTemplateTestDescriptor method prepare.
// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) throws Exception {
ExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(context.getExtensionRegistry(), getTestMethod());
// The test instance should be properly maintained by the enclosing class's ExtensionContext.
Object testInstance = context.getExtensionContext().getTestInstance().orElse(null);
ExtensionContext extensionContext = new TestTemplateExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, context.getConfigurationParameters(), testInstance);
// @formatter:off
return context.extend().withExtensionRegistry(registry).withExtensionContext(extensionContext).build();
// @formatter:on
}
Aggregations