use of org.eclipse.xtext.testing.IInjectorProvider in project n4js by eclipse.
the class XtextParametrizedRunner method allParameters.
/**
* Implements behavior from: org.junit.runners.Parameterized
*/
@SuppressWarnings("unchecked")
private Iterable<Object> allParameters() throws Throwable {
FrameworkMethod parametersMethod = getParametersMethod();
if (parametersMethod != null) {
Object parameters = parametersMethod.invokeExplosively(null);
if (parameters instanceof Iterable) {
return (Iterable<Object>) parameters;
} else {
throw parametersMethodReturnedWrongType(parametersMethod);
}
}
FrameworkMethod parametersProviderMethod = getParametersProviderMethod();
if (parametersProviderMethod != null) {
Object provider = parametersProviderMethod.invokeExplosively(null);
if (provider instanceof Provider<?>) {
IInjectorProvider injectorProvider = InjectorProviders.getOrCreateInjectorProvider(getTestClass());
if (injectorProvider != null) {
Injector injector = injectorProvider.getInjector();
if (injector != null)
injector.injectMembers(provider);
}
Object parameters = ((Provider<?>) provider).get();
if (parameters instanceof Iterable) {
return (Iterable<Object>) parameters;
}
}
throw parametersProviderMethodReturnedWrongType(parametersProviderMethod);
}
throw new Exception("No public static parameters method on class " + getTestClass().getName());
}
use of org.eclipse.xtext.testing.IInjectorProvider in project xtext-core by eclipse.
the class InjectionExtension method afterEach.
@Override
public void afterEach(ExtensionContext context) throws Exception {
IInjectorProvider injectorProvider = getOrCreateInjectorProvider(context);
restoreRegistry(injectorProvider, context);
}
use of org.eclipse.xtext.testing.IInjectorProvider in project xtext-core by eclipse.
the class AbstractScenarioRunner method methodBlock.
@Override
protected Statement methodBlock(final FrameworkMethod method) {
IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
registryConfigurator.setupRegistry();
final Statement methodBlock = superMethodBlock(method);
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
try {
methodBlock.evaluate();
throw new AssumptionViolatedException("Method " + method.getName() + " did parse any input");
} finally {
registryConfigurator.restoreRegistry();
}
} catch (TestDataCarrier testData) {
process(testData.getData());
}
}
};
}
use of org.eclipse.xtext.testing.IInjectorProvider in project xtext-core by eclipse.
the class AbstractParallelScenarioRunner method childrenInvoker.
@Override
protected Statement childrenInvoker(final RunNotifier notifier) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
WrappingInjectorProvider wrapped = getOrCreateInjectorProvider();
wrapped.setupRegistry();
try {
prepareChildren(notifier);
} finally {
wrapped.restoreRegistry();
}
IInjectorProvider delegate = wrapped.getDelegate();
if (delegate instanceof IRegistryConfigurator) {
IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
registryConfigurator.setupRegistry();
try {
runChildren(notifier);
} finally {
registryConfigurator.restoreRegistry();
}
} else {
runChildren(notifier);
}
}
};
}
Aggregations