Java Code Examples for org.eclipse.xtext.testing.IRegistryConfigurator#setupRegistry()
The following examples show how to use
org.eclipse.xtext.testing.IRegistryConfigurator#setupRegistry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractScenarioRunner.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void process(String data) throws Exception { IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate(); if (delegate instanceof IRegistryConfigurator) { IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate; registryConfigurator.setupRegistry(); try { ScenarioProcessor processor = delegate.getInjector().getInstance(processorClass); String preProcessed = processor.preProcess(data); if (preProcessed == null) { throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data); } doProcess(preProcessed, processor); } finally { registryConfigurator.restoreRegistry(); } } }
Example 2
Source File: AbstractInjectorExtension.java From sarl with Apache License 2.0 | 6 votes |
private static IInjectorProvider createInjectorProvider(ExtensionContext context) { InjectWith injectWith = context.getRequiredTestClass().getAnnotation(InjectWith.class); if (injectWith != null) { Class<? extends IInjectorProvider> klass = injectWith.value(); try { // TODO this mode of creation is not efficient, but it ensures that the injector providers are really reset. final IInjectorProvider injectorProvider = klass.getDeclaredConstructor().newInstance(); if (injectorProvider instanceof IRegistryConfigurator) { final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider; registryConfigurator.setupRegistry(); } return injectorProvider; } catch (Exception e) { throwUncheckedException(e); } } throw new IllegalStateException("Expected valid @InjectWith annotation"); }
Example 3
Source File: AbstractParallelScenarioRunner.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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); } } }; }
Example 4
Source File: InjectionExtension.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void beforeEach(ExtensionContext context) throws Exception { IInjectorProvider injectorProvider = getOrCreateInjectorProvider(context); if (injectorProvider instanceof IRegistryConfigurator) { final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider; registryConfigurator.setupRegistry(); } if (injectorProvider != null) { Injector injector = injectorProvider.getInjector(); if (injector != null) { Object testInstance = context.getRequiredTestInstance(); injector.injectMembers(testInstance); try { TestInstances requiredTestInstances = context.getRequiredTestInstances(); for (Object o : requiredTestInstances.getEnclosingInstances()) { injector.injectMembers(o); } } catch (NoSuchMethodError e) { if (!Modifier.isStatic(testInstance.getClass().getModifiers())) { if (testInstance.getClass().getDeclaringClass() != null) { throw new ExtensionConfigurationException("Injection of nested classes needs Junit5 >= 5.4", e); } } // OK, getRequiredTestInstances is not there in Junit5 < 5.4 } } } }