Search in sources :

Example 1 with TestTemplateInvocationContextProvider

use of org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider 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)

Aggregations

Method (java.lang.reflect.Method)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors.toList (java.util.stream.Collectors.toList)1 API (org.apiguardian.api.API)1 INTERNAL (org.apiguardian.api.API.Status.INTERNAL)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 TestTemplateInvocationContext (org.junit.jupiter.api.extension.TestTemplateInvocationContext)1 TestTemplateInvocationContextProvider (org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider)1 ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation (org.junit.jupiter.engine.descriptor.ExtensionUtils.populateNewExtensionRegistryFromExtendWithAnnotation)1 JupiterEngineExecutionContext (org.junit.jupiter.engine.execution.JupiterEngineExecutionContext)1 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)1 Preconditions (org.junit.platform.commons.util.Preconditions)1 TestDescriptor (org.junit.platform.engine.TestDescriptor)1 UniqueId (org.junit.platform.engine.UniqueId)1