Search in sources :

Example 6 with IInjectorProvider

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());
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) Injector(com.google.inject.Injector) FrameworkMethod(org.junit.runners.model.FrameworkMethod) IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) Provider(com.google.inject.Provider)

Example 7 with IInjectorProvider

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);
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider)

Example 8 with IInjectorProvider

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());
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 9 with IInjectorProvider

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);
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Aggregations

IInjectorProvider (org.eclipse.xtext.testing.IInjectorProvider)9 IRegistryConfigurator (org.eclipse.xtext.testing.IRegistryConfigurator)3 AssumptionViolatedException (org.junit.AssumptionViolatedException)3 Injector (com.google.inject.Injector)2 InjectWith (org.eclipse.xtext.testing.InjectWith)2 ScenarioProcessor (org.eclipse.xtext.testing.smoketest.ScenarioProcessor)2 Exceptions.throwUncheckedException (org.eclipse.xtext.util.Exceptions.throwUncheckedException)2 Statement (org.junit.runners.model.Statement)2 Provider (com.google.inject.Provider)1 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 FrameworkMethod (org.junit.runners.model.FrameworkMethod)1