Search in sources :

Example 1 with MutableExtensionRegistry

use of org.junit.jupiter.engine.extension.MutableExtensionRegistry in project junit5 by junit-team.

the class TestMethodTestDescriptor method populateNewExtensionRegistry.

protected MutableExtensionRegistry populateNewExtensionRegistry(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(context.getExtensionRegistry(), getTestMethod());
    registerExtensionsFromExecutableParameters(registry, getTestMethod());
    return registry;
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry)

Example 2 with MutableExtensionRegistry

use of org.junit.jupiter.engine.extension.MutableExtensionRegistry in project junit5 by junit-team.

the class TestTemplateInvocationTestDescriptor method populateNewExtensionRegistry.

@Override
protected MutableExtensionRegistry populateNewExtensionRegistry(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry registry = super.populateNewExtensionRegistry(context);
    invocationContext.getAdditionalExtensions().forEach(extension -> registry.registerExtension(extension, invocationContext));
    return registry;
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry)

Example 3 with MutableExtensionRegistry

use of org.junit.jupiter.engine.extension.MutableExtensionRegistry in project junit5 by junit-team.

the class ClassBasedTestDescriptor method prepare.

@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry 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);
    // Resolve the TestInstanceFactory at the class level in order to fail
    // the entire class in case of configuration errors (e.g., more than
    // one factory registered per class).
    this.testInstanceFactory = resolveTestInstanceFactory(registry);
    if (this.testInstanceFactory == null) {
        registerExtensionsFromConstructorParameters(registry, this.testClass);
    }
    this.beforeAllMethods = findBeforeAllMethods(this.testClass, this.lifecycle == Lifecycle.PER_METHOD);
    this.afterAllMethods = findAfterAllMethods(this.testClass, this.lifecycle == Lifecycle.PER_METHOD);
    this.beforeAllMethods.forEach(method -> registerExtensionsFromExecutableParameters(registry, method));
    // Since registerBeforeEachMethodAdapters() and registerAfterEachMethodAdapters() also
    // invoke registerExtensionsFromExecutableParameters(), we invoke those methods before
    // invoking registerExtensionsFromExecutableParameters() for @AfterAll methods,
    // thereby ensuring proper registration order for extensions registered via @ExtendWith
    // on parameters in lifecycle methods.
    registerBeforeEachMethodAdapters(registry);
    registerAfterEachMethodAdapters(registry);
    this.afterAllMethods.forEach(method -> registerExtensionsFromExecutableParameters(registry, method));
    ThrowableCollector throwableCollector = createThrowableCollector();
    ExecutableInvoker executableInvoker = new DefaultExecutableInvoker(context);
    ClassExtensionContext extensionContext = new ClassExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, this.lifecycle, context.getConfiguration(), throwableCollector, executableInvoker);
    // @formatter:off
    return context.extend().withTestInstancesProvider(testInstancesProvider(context, extensionContext)).withExtensionRegistry(registry).withExtensionContext(extensionContext).withThrowableCollector(throwableCollector).build();
// @formatter:on
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker) InterceptingExecutableInvoker(org.junit.jupiter.engine.execution.InterceptingExecutableInvoker) ExecutableInvoker(org.junit.jupiter.api.extension.ExecutableInvoker) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker) ThrowableCollector(org.junit.platform.engine.support.hierarchical.ThrowableCollector) JupiterThrowableCollectorFactory.createThrowableCollector(org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector)

Example 4 with MutableExtensionRegistry

use of org.junit.jupiter.engine.extension.MutableExtensionRegistry in project junit5 by junit-team.

the class JupiterEngineExecutionContextTests method canOverrideAttributeWhenContextIsExtended.

@Test
void canOverrideAttributeWhenContextIsExtended() {
    ExtensionContext extensionContext = mock(ExtensionContext.class);
    MutableExtensionRegistry extensionRegistry = MutableExtensionRegistry.createRegistryWithDefaultExtensions(configuration);
    TestInstancesProvider testInstancesProvider = mock(TestInstancesProvider.class);
    ExtensionContext newExtensionContext = mock(ExtensionContext.class);
    JupiterEngineExecutionContext newContext = // 
    originalContext.extend().withExtensionContext(// 
    extensionContext).withExtensionRegistry(// 
    extensionRegistry).withTestInstancesProvider(// 
    testInstancesProvider).build().extend().withExtensionContext(// 
    newExtensionContext).build();
    assertSame(newExtensionContext, newContext.getExtensionContext());
    assertSame(extensionRegistry, newContext.getExtensionRegistry());
    assertSame(testInstancesProvider, newContext.getTestInstancesProvider());
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Test(org.junit.jupiter.api.Test)

Example 5 with MutableExtensionRegistry

use of org.junit.jupiter.engine.extension.MutableExtensionRegistry in project graylog2-server by Graylog2.

the class ContainerMatrixEngineDescriptor method prepare.

@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry extensionRegistry = MutableExtensionRegistry.createRegistryWithDefaultExtensions(context.getConfiguration());
    EngineExecutionListener executionListener = context.getExecutionListener();
    ExtensionContext extensionContext = new ContainerMatrixExtensionContext(executionListener, this, context.getConfiguration());
    // @formatter:off
    return context.extend().withExtensionRegistry(extensionRegistry).withExtensionContext(extensionContext).build();
// @formatter:on
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext)

Aggregations

MutableExtensionRegistry (org.junit.jupiter.engine.extension.MutableExtensionRegistry)9 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)5 ExecutableInvoker (org.junit.jupiter.api.extension.ExecutableInvoker)4 DefaultExecutableInvoker (org.junit.jupiter.engine.execution.DefaultExecutableInvoker)4 Test (org.junit.jupiter.api.Test)2 TestInstances (org.junit.jupiter.api.extension.TestInstances)2 InterceptingExecutableInvoker (org.junit.jupiter.engine.execution.InterceptingExecutableInvoker)2 JupiterThrowableCollectorFactory.createThrowableCollector (org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ThrowableCollector (org.junit.platform.engine.support.hierarchical.ThrowableCollector)2