use of org.junit.jupiter.engine.extension.ExtensionRegistry 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.engine.extension.ExtensionRegistry in project junit5 by junit-team.
the class JupiterEngineExecutionContextTests method extendWithAllAttributes.
@Test
void extendWithAllAttributes() {
UniqueId uniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(uniqueId, getClass());
ClassExtensionContext extensionContext = new ClassExtensionContext(null, null, classTestDescriptor, configParams, null);
ExtensionRegistry extensionRegistry = ExtensionRegistry.createRegistryWithDefaultExtensions(configParams);
TestInstanceProvider testInstanceProvider = mock(TestInstanceProvider.class);
JupiterEngineExecutionContext newContext = //
originalContext.extend().withExtensionContext(//
extensionContext).withExtensionRegistry(//
extensionRegistry).withTestInstanceProvider(//
testInstanceProvider).build();
assertSame(extensionContext, newContext.getExtensionContext());
assertSame(extensionRegistry, newContext.getExtensionRegistry());
assertSame(testInstanceProvider, newContext.getTestInstanceProvider());
}
use of org.junit.jupiter.engine.extension.ExtensionRegistry in project junit-dataprovider by TNG.
the class AbstractUseDataProviderArgumentProvider method invokeDataProviderMethodToRetrieveData.
/**
* Retrieves the test data from given dataprovider method.
*
* @param dataProviderMethod the dataprovider method that gives the parameters; never {@code null}
* @param cacheDataProviderResult determines if the dataprovider result should be cached using
* {@code dataProviderMethod} as key
* @param context the execution context to use to create a {@link TestInfo} if required; never {@code null}
*
* @return a list of methods, each method bound to a parameter combination returned by the dataprovider
* @throws NullPointerException if and only if one of the given arguments is {@code null}
*/
protected Object invokeDataProviderMethodToRetrieveData(Method dataProviderMethod, boolean cacheDataProviderResult, ExtensionContext context) {
checkNotNull(dataProviderMethod, "'dataProviderMethod' must not be null");
checkNotNull(context, "'context' must not be null");
Store store = context.getRoot().getStore(NAMESPACE_USE_DATAPROVIDER);
Object cached = store.get(dataProviderMethod);
if (cached != null) {
return cached;
}
try {
// TODO how to not require junit-jupiter-engine dependency and reuse already existing ExtensionRegistry?
ExtensionRegistry extensionRegistry = createRegistryWithDefaultExtensions(emptyConfigurationParameters());
Object data = executableInvoker.invoke(dataProviderMethod, context.getTestInstance().orElse(null), context, extensionRegistry);
if (cacheDataProviderResult) {
store.put(dataProviderMethod, data);
}
return data;
} catch (Exception e) {
throw new ParameterResolutionException(String.format("Exception while invoking dataprovider method '%s': %s", dataProviderMethod.getName(), e.getMessage()), e);
}
}
Aggregations