Search in sources :

Example 1 with ExecutableInvoker

use of org.junit.jupiter.api.extension.ExecutableInvoker 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 2 with ExecutableInvoker

use of org.junit.jupiter.api.extension.ExecutableInvoker in project junit5 by junit-team.

the class JupiterEngineDescriptor method prepare.

@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry extensionRegistry = MutableExtensionRegistry.createRegistryWithDefaultExtensions(context.getConfiguration());
    EngineExecutionListener executionListener = context.getExecutionListener();
    ExecutableInvoker executableInvoker = new DefaultExecutableInvoker(context);
    ExtensionContext extensionContext = new JupiterEngineExtensionContext(executionListener, this, context.getConfiguration(), executableInvoker);
    // @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) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker) ExecutableInvoker(org.junit.jupiter.api.extension.ExecutableInvoker) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker)

Example 3 with ExecutableInvoker

use of org.junit.jupiter.api.extension.ExecutableInvoker in project junit5 by junit-team.

the class TestMethodTestDescriptor method prepare.

// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
    MutableExtensionRegistry registry = populateNewExtensionRegistry(context);
    ThrowableCollector throwableCollector = createThrowableCollector();
    ExecutableInvoker executableInvoker = new DefaultExecutableInvoker(context);
    MethodExtensionContext extensionContext = new MethodExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, context.getConfiguration(), throwableCollector, executableInvoker);
    throwableCollector.execute(() -> {
        TestInstances testInstances = context.getTestInstancesProvider().getTestInstances(registry, throwableCollector);
        extensionContext.setTestInstances(testInstances);
    });
    // @formatter:off
    return context.extend().withExtensionRegistry(registry).withExtensionContext(extensionContext).withThrowableCollector(throwableCollector).build();
// @formatter:on
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry) ExecutableInvoker(org.junit.jupiter.api.extension.ExecutableInvoker) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker) InterceptingExecutableInvoker(org.junit.jupiter.engine.execution.InterceptingExecutableInvoker) TestInstances(org.junit.jupiter.api.extension.TestInstances) 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 ExecutableInvoker

use of org.junit.jupiter.api.extension.ExecutableInvoker in project junit5 by junit-team.

the class TestTemplateTestDescriptor method prepare.

// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) throws Exception {
    MutableExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(context.getExtensionRegistry(), getTestMethod());
    // The test instance should be properly maintained by the enclosing class's ExtensionContext.
    TestInstances testInstances = context.getExtensionContext().getTestInstances().orElse(null);
    ExecutableInvoker executableInvoker = new DefaultExecutableInvoker(context);
    ExtensionContext extensionContext = new TestTemplateExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, context.getConfiguration(), testInstances, executableInvoker);
    // @formatter:off
    return context.extend().withExtensionRegistry(registry).withExtensionContext(extensionContext).build();
// @formatter:on
}
Also used : MutableExtensionRegistry(org.junit.jupiter.engine.extension.MutableExtensionRegistry) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker) ExecutableInvoker(org.junit.jupiter.api.extension.ExecutableInvoker) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) TestInstances(org.junit.jupiter.api.extension.TestInstances) DefaultExecutableInvoker(org.junit.jupiter.engine.execution.DefaultExecutableInvoker)

Aggregations

ExecutableInvoker (org.junit.jupiter.api.extension.ExecutableInvoker)4 DefaultExecutableInvoker (org.junit.jupiter.engine.execution.DefaultExecutableInvoker)4 MutableExtensionRegistry (org.junit.jupiter.engine.extension.MutableExtensionRegistry)4 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)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 ThrowableCollector (org.junit.platform.engine.support.hierarchical.ThrowableCollector)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)1