Search in sources :

Example 11 with ExtensionRegistry

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
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector)

Example 12 with ExtensionRegistry

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;
        }
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Executable(org.junit.jupiter.api.function.Executable) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector)

Example 13 with ExtensionRegistry

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);
}
Also used : ExecutableInvoker(org.junit.jupiter.engine.execution.ExecutableInvoker) AfterEachMethodAdapter(org.junit.jupiter.engine.execution.AfterEachMethodAdapter) ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation(org.junit.jupiter.engine.descriptor.ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation) BiFunction(java.util.function.BiFunction) API(org.apiguardian.api.API) UniqueId(org.junit.platform.engine.UniqueId) AfterTestExecutionCallback(org.junit.jupiter.api.extension.AfterTestExecutionCallback) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) BeforeEachMethodAdapter(org.junit.jupiter.engine.execution.BeforeEachMethodAdapter) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) BeforeTestExecutionCallback(org.junit.jupiter.api.extension.BeforeTestExecutionCallback) Extension(org.junit.jupiter.api.extension.Extension) JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) List(java.util.List) AfterEachCallback(org.junit.jupiter.api.extension.AfterEachCallback) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) Executable(org.junit.jupiter.api.function.Executable) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) BeforeEachCallback(org.junit.jupiter.api.extension.BeforeEachCallback) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) Method(java.lang.reflect.Method) TestExecutionExceptionHandler(org.junit.jupiter.api.extension.TestExecutionExceptionHandler) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry)

Example 14 with ExtensionRegistry

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);
}
Also used : ExecutableInvoker(org.junit.jupiter.engine.execution.ExecutableInvoker) AfterEachMethodAdapter(org.junit.jupiter.engine.execution.AfterEachMethodAdapter) ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation(org.junit.jupiter.engine.descriptor.ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation) BiFunction(java.util.function.BiFunction) API(org.apiguardian.api.API) UniqueId(org.junit.platform.engine.UniqueId) AfterTestExecutionCallback(org.junit.jupiter.api.extension.AfterTestExecutionCallback) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) BeforeEachMethodAdapter(org.junit.jupiter.engine.execution.BeforeEachMethodAdapter) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) BeforeTestExecutionCallback(org.junit.jupiter.api.extension.BeforeTestExecutionCallback) Extension(org.junit.jupiter.api.extension.Extension) JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) List(java.util.List) AfterEachCallback(org.junit.jupiter.api.extension.AfterEachCallback) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) Executable(org.junit.jupiter.api.function.Executable) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) BeforeEachCallback(org.junit.jupiter.api.extension.BeforeEachCallback) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) Method(java.lang.reflect.Method) TestExecutionExceptionHandler(org.junit.jupiter.api.extension.TestExecutionExceptionHandler) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry)

Example 15 with ExtensionRegistry

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
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry)

Aggregations

ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)18 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)12 ThrowableCollector (org.junit.jupiter.engine.execution.ThrowableCollector)10 Method (java.lang.reflect.Method)4 Executable (org.junit.jupiter.api.function.Executable)4 UniqueId (org.junit.platform.engine.UniqueId)4 List (java.util.List)3 Optional (java.util.Optional)3 API (org.apiguardian.api.API)3 INTERNAL (org.apiguardian.api.API.Status.INTERNAL)3 ParameterResolutionException (org.junit.jupiter.api.extension.ParameterResolutionException)3 BiFunction (java.util.function.BiFunction)2 Test (org.junit.jupiter.api.Test)2 AfterEachCallback (org.junit.jupiter.api.extension.AfterEachCallback)2 AfterTestExecutionCallback (org.junit.jupiter.api.extension.AfterTestExecutionCallback)2 BeforeEachCallback (org.junit.jupiter.api.extension.BeforeEachCallback)2 BeforeTestExecutionCallback (org.junit.jupiter.api.extension.BeforeTestExecutionCallback)2 Extension (org.junit.jupiter.api.extension.Extension)2 Store (org.junit.jupiter.api.extension.ExtensionContext.Store)2 TestExecutionExceptionHandler (org.junit.jupiter.api.extension.TestExecutionExceptionHandler)2