Search in sources :

Example 1 with JupiterEngineExecutionContext

use of org.junit.jupiter.engine.execution.JupiterEngineExecutionContext in project junit5 by junit-team.

the class TestFactoryTestDescriptorTests method before.

@BeforeEach
void before() throws Exception {
    extensionContext = mock(ExtensionContext.class);
    isClosed = false;
    context = new JupiterEngineExecutionContext(null, null).extend().withThrowableCollector(new ThrowableCollector()).withExtensionContext(extensionContext).build();
    Method testMethod = CustomStreamTestCase.class.getDeclaredMethod("customStream");
    descriptor = new TestFactoryTestDescriptor(UniqueId.forEngine("engine"), CustomStreamTestCase.class, testMethod);
    when(extensionContext.getTestMethod()).thenReturn(Optional.of(testMethod));
}
Also used : JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Method(java.lang.reflect.Method) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with JupiterEngineExecutionContext

use of org.junit.jupiter.engine.execution.JupiterEngineExecutionContext in project junit5 by junit-team.

the class TestTemplateTestDescriptor method execute.

@Override
public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) throws Exception {
    ExtensionContext extensionContext = context.getExtensionContext();
    List<TestTemplateInvocationContextProvider> providers = validateProviders(extensionContext, context.getExtensionRegistry());
    AtomicInteger invocationIndex = new AtomicInteger();
    // @formatter:off
    providers.stream().flatMap(provider -> provider.provideTestTemplateInvocationContexts(extensionContext)).map(invocationContext -> createInvocationTestDescriptor(invocationContext, invocationIndex.incrementAndGet())).filter(Optional::isPresent).map(Optional::get).forEach(invocationTestDescriptor -> execute(dynamicTestExecutor, invocationTestDescriptor));
    // @formatter:on
    validateWasAtLeastInvokedOnce(invocationIndex.get());
    return context;
}
Also used : Preconditions(org.junit.platform.commons.util.Preconditions) ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation(org.junit.jupiter.engine.descriptor.ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation) API(org.apiguardian.api.API) UniqueId(org.junit.platform.engine.UniqueId) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) Optional(java.util.Optional) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider) TestDescriptor(org.junit.platform.engine.TestDescriptor) Method(java.lang.reflect.Method) Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider)

Example 3 with JupiterEngineExecutionContext

use of org.junit.jupiter.engine.execution.JupiterEngineExecutionContext 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 4 with JupiterEngineExecutionContext

use of org.junit.jupiter.engine.execution.JupiterEngineExecutionContext 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)

Aggregations

Method (java.lang.reflect.Method)4 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)4 JupiterEngineExecutionContext (org.junit.jupiter.engine.execution.JupiterEngineExecutionContext)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 ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation (org.junit.jupiter.engine.descriptor.ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation)3 ThrowableCollector (org.junit.jupiter.engine.execution.ThrowableCollector)3 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)3 TestDescriptor (org.junit.platform.engine.TestDescriptor)3 UniqueId (org.junit.platform.engine.UniqueId)3 BiFunction (java.util.function.BiFunction)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 TestExecutionExceptionHandler (org.junit.jupiter.api.extension.TestExecutionExceptionHandler)2 Executable (org.junit.jupiter.api.function.Executable)2