use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class JupiterEngineExecutionContextTests method canOverrideAttributeWhenContextIsExtended.
@Test
void canOverrideAttributeWhenContextIsExtended() {
UniqueId uniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(uniqueId, getClass());
ClassExtensionContext extensionContext = new ClassExtensionContext(null, null, classTestDescriptor, configParams, null);
ExtensionRegistry extensionRegistry = ExtensionRegistry.createRegistryWithDefaultExtensions(configParams);
TestInstanceProvider testInstanceProvider = mock(TestInstanceProvider.class);
ClassExtensionContext newExtensionContext = new ClassExtensionContext(extensionContext, null, classTestDescriptor, configParams, null);
JupiterEngineExecutionContext newContext = //
originalContext.extend().withExtensionContext(//
extensionContext).withExtensionRegistry(//
extensionRegistry).withTestInstanceProvider(//
testInstanceProvider).build().extend().withExtensionContext(//
newExtensionContext).build();
assertSame(newExtensionContext, newContext.getExtensionContext());
assertSame(extensionRegistry, newContext.getExtensionRegistry());
assertSame(testInstanceProvider, newContext.getTestInstanceProvider());
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry 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.extension.ExtensionRegistry in project junit5 by junit-team.
the class TestTemplateInvocationTestDescriptor method populateNewExtensionRegistry.
@Override
protected ExtensionRegistry populateNewExtensionRegistry(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = super.populateNewExtensionRegistry(context);
invocationContext.getAdditionalExtensions().forEach(extension -> registry.registerExtension(extension, invocationContext));
return registry;
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry 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.extension.ExtensionRegistry 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