Search in sources :

Example 1 with TestInstances

use of org.junit.jupiter.api.extension.TestInstances in project tomee by apache.

the class TomEEEmbeddedExtension method doInject.

private void doInject(final ExtensionContext extensionContext) {
    TestInstances oTestInstances = extensionContext.getTestInstances().orElseThrow(() -> new OpenEJBRuntimeException("No test instances available for the given extension context."));
    List<Object> testInstances = oTestInstances.getAllInstances();
    testInstances.forEach(t -> {
        try {
            BASE.composerInject(t);
        } catch (Exception e) {
            throw new OpenEJBRuntimeException(e);
        }
    });
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TestInstances(org.junit.jupiter.api.extension.TestInstances) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 2 with TestInstances

use of org.junit.jupiter.api.extension.TestInstances in project tomee by apache.

the class ApplicationComposerPerXYExtensionBase method doStart.

void doStart(final ExtensionContext extensionContext) throws Exception {
    TestInstances oTestInstances = extensionContext.getTestInstances().orElseThrow(() -> new OpenEJBRuntimeException("No test instances available for the given extension context."));
    List<Object> testInstances = oTestInstances.getAllInstances();
    ApplicationComposers delegate = extensionContext.getStore(NAMESPACE).get(ApplicationComposers.class, ApplicationComposers.class);
    testInstances.forEach(t -> {
        try {
            delegate.before(t);
        } catch (Exception e) {
            throw new OpenEJBRuntimeException(e);
        }
    });
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TestInstances(org.junit.jupiter.api.extension.TestInstances) ApplicationComposers(org.apache.openejb.testing.ApplicationComposers) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 3 with TestInstances

use of org.junit.jupiter.api.extension.TestInstances in project tomee by apache.

the class ApplicationComposerPerXYExtensionBase method doInject.

void doInject(final ExtensionContext extensionContext) {
    TestInstances oTestInstances = extensionContext.getTestInstances().orElseThrow(() -> new OpenEJBRuntimeException("No test instances available for the given extension context."));
    List<Object> testInstances = oTestInstances.getAllInstances();
    testInstances.forEach(target -> {
        try {
            doInject(target, extensionContext);
        } catch (Exception e) {
            throw new OpenEJBRuntimeException(e);
        }
    });
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TestInstances(org.junit.jupiter.api.extension.TestInstances) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 4 with TestInstances

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

the class ClassBasedTestDescriptor method invokeMethodInExtensionContext.

private void invokeMethodInExtensionContext(Method method, ExtensionContext context, ExtensionRegistry registry, VoidMethodInterceptorCall interceptorCall) {
    TestInstances testInstances = context.getRequiredTestInstances();
    Object target = testInstances.findInstance(this.testClass).orElseThrow(() -> new JUnitException("Failed to find instance for method: " + method.toGenericString()));
    executableInvoker.invoke(method, target, context, registry, ReflectiveInterceptorCall.ofVoidMethod(interceptorCall));
}
Also used : JUnitException(org.junit.platform.commons.JUnitException) TestInstances(org.junit.jupiter.api.extension.TestInstances) DefaultTestInstances(org.junit.jupiter.engine.execution.DefaultTestInstances)

Example 5 with TestInstances

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

the class ClassBasedTestDescriptor method instantiateAndPostProcessTestInstance.

private TestInstances instantiateAndPostProcessTestInstance(JupiterEngineExecutionContext parentExecutionContext, ExtensionContext extensionContext, ExtensionRegistry registry, ExtensionRegistrar registrar, ThrowableCollector throwableCollector) {
    TestInstances instances = instantiateTestClass(parentExecutionContext, registry, registrar, extensionContext, throwableCollector);
    throwableCollector.execute(() -> {
        invokeTestInstancePostProcessors(instances.getInnermostInstance(), registry, extensionContext);
        // In addition, we register extensions from instance fields here since the
        // best time to do that is immediately following test class instantiation
        // and post processing.
        registerExtensionsFromFields(registrar, this.testClass, instances.getInnermostInstance());
    });
    return instances;
}
Also used : TestInstances(org.junit.jupiter.api.extension.TestInstances) DefaultTestInstances(org.junit.jupiter.engine.execution.DefaultTestInstances)

Aggregations

TestInstances (org.junit.jupiter.api.extension.TestInstances)14 DefaultTestInstances (org.junit.jupiter.engine.execution.DefaultTestInstances)7 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 Test (org.junit.jupiter.api.Test)3 ExecutableInvoker (org.junit.jupiter.api.extension.ExecutableInvoker)2 DefaultExecutableInvoker (org.junit.jupiter.engine.execution.DefaultExecutableInvoker)2 MutableExtensionRegistry (org.junit.jupiter.engine.extension.MutableExtensionRegistry)2 JupiterThrowableCollectorFactory.createThrowableCollector (org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector)2 ThrowableCollector (org.junit.platform.engine.support.hierarchical.ThrowableCollector)2 ApplicationComposers (org.apache.openejb.testing.ApplicationComposers)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 InterceptingExecutableInvoker (org.junit.jupiter.engine.execution.InterceptingExecutableInvoker)1 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)1 JUnitException (org.junit.platform.commons.JUnitException)1 Config (org.neo4j.configuration.Config)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 Neo4jLayout (org.neo4j.io.layout.Neo4jLayout)1 TestDirectory (org.neo4j.test.rule.TestDirectory)1