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);
}
});
}
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);
}
});
}
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);
}
});
}
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));
}
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;
}
Aggregations