use of org.junit.jupiter.api.extension.ExtensionContext 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);
}
use of org.junit.jupiter.api.extension.ExtensionContext 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);
}
use of org.junit.jupiter.api.extension.ExtensionContext 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
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class JupiterEngineDescriptor method prepare.
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(context.getConfigurationParameters());
EngineExecutionListener executionListener = context.getExecutionListener();
ExtensionContext extensionContext = new JupiterEngineExtensionContext(executionListener, this, context.getConfigurationParameters());
// @formatter:off
return context.extend().withExtensionRegistry(extensionRegistry).withExtensionContext(extensionContext).build();
// @formatter:on
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class TestFactoryTestDescriptor method invokeTestMethod.
// --- Node ----------------------------------------------------------------
@Override
protected void invokeTestMethod(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) {
ExtensionContext extensionContext = context.getExtensionContext();
context.getThrowableCollector().execute(() -> {
Object instance = extensionContext.getRequiredTestInstance();
Object testFactoryMethodResult = executableInvoker.invoke(getTestMethod(), instance, extensionContext, context.getExtensionRegistry());
TestSource source = getSource().orElseThrow(() -> new JUnitException("Illegal state: TestSource must be present"));
try (Stream<DynamicNode> dynamicNodeStream = toDynamicNodeStream(testFactoryMethodResult)) {
int index = 1;
Iterator<DynamicNode> iterator = dynamicNodeStream.iterator();
while (iterator.hasNext()) {
DynamicNode dynamicNode = iterator.next();
Optional<JupiterTestDescriptor> descriptor = createDynamicDescriptor(this, dynamicNode, index++, source, getDynamicDescendantFilter());
descriptor.ifPresent(dynamicTestExecutor::execute);
}
} catch (ClassCastException ex) {
throw invalidReturnTypeException(ex);
}
});
}
Aggregations