Search in sources :

Example 21 with InitializationError

use of org.junit.runners.model.InitializationError in project gerrit by GerritCodeReview.

the class ConfigSuite method runnersFor.

private static List<Runner> runnersFor(Class<?> clazz) {
    Method defaultConfig = getDefaultConfig(clazz);
    List<Method> configs = getConfigs(clazz);
    Map<String, org.eclipse.jgit.lib.Config> configMap = callConfigMapMethod(getConfigMap(clazz), configs);
    Field parameterField = getOnlyField(clazz, Parameter.class);
    checkArgument(parameterField != null, "No @ConfigSuite.Parameter found");
    Field nameField = getOnlyField(clazz, Name.class);
    List<Runner> result = Lists.newArrayListWithCapacity(configs.size() + 1);
    try {
        result.add(new ConfigRunner(clazz, parameterField, nameField, null, callConfigMethod(defaultConfig)));
        for (Method m : configs) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, m.getName(), callConfigMethod(m)));
        }
        for (Map.Entry<String, org.eclipse.jgit.lib.Config> e : configMap.entrySet()) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, e.getKey(), e.getValue()));
        }
        return result;
    } catch (InitializationError e) {
        System.err.println("Errors initializing runners:");
        for (Throwable t : e.getCauses()) {
            t.printStackTrace();
        }
        throw new RuntimeException(e);
    }
}
Also used : BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) InitializationError(org.junit.runners.model.InitializationError) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Field(java.lang.reflect.Field) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with InitializationError

use of org.junit.runners.model.InitializationError in project xtext-core by eclipse.

the class RunnerBuilder method getScenarios.

private static Scenario[] getScenarios(Class<?> klass, boolean completeInput) throws InitializationError {
    Scenarios annotation = klass.getAnnotation(Scenarios.class);
    if (annotation == null) {
        return Scenario.values();
    } else if (completeInput) {
        throw new InitializationError("Must not use ProcessedBy.processCompleteInput together with the Scenarios annotation");
    }
    Scenario[] result = annotation.value();
    if (result.length == 0) {
        throw new InitializationError("Must at least specify one smoke test scenario or omit the Scenarios annotation");
    }
    return result;
}
Also used : InitializationError(org.junit.runners.model.InitializationError) Scenarios(org.eclipse.xtext.testing.smoketest.Scenarios) Scenario(org.eclipse.xtext.testing.smoketest.Scenario)

Example 23 with InitializationError

use of org.junit.runners.model.InitializationError in project janusgraph by JanusGraph.

the class BerkeleyProcessComputerSuite method getTestList.

private static Class<?>[] getTestList() throws InitializationError {
    try {
        final Field field = ProcessComputerSuite.class.getDeclaredField("allTests");
        field.setAccessible(true);
        return (Class<?>[]) ArrayUtils.removeElement((Class<?>[]) field.get(null), TraversalInterruptionComputerTest.class);
    } catch (ReflectiveOperationException e) {
        throw new InitializationError("Unable to create test list");
    }
}
Also used : TraversalInterruptionComputerTest(org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest) Field(java.lang.reflect.Field) InitializationError(org.junit.runners.model.InitializationError)

Example 24 with InitializationError

use of org.junit.runners.model.InitializationError in project intellij-community by JetBrains.

the class AllTestsSuite method getSuiteClasses.

private static Class<?>[] getSuiteClasses(Class<?> klass) throws InitializationError {
    TestPackage annotation = klass.getAnnotation(TestPackage.class);
    if (annotation == null)
        throw new InitializationError("No test package specified");
    String testPackage = annotation.value();
    SlowPolicy policy = annotation.policy();
    TestCaseLoader loader = new TestCaseLoader("", true);
    try {
        TestAll.fillTestCases(loader, testPackage, TestAll.getClassRoots());
    } catch (IOException e) {
        throw new InitializationError(e);
    }
    List<Class<?>> result = ContainerUtil.newArrayList();
    for (Class aClass : loader.getClasses()) {
        if (policy == SlowPolicy.ALL) {
            result.add(aClass);
        } else {
            boolean slow = isSlow(aClass);
            if (slow && policy == SlowPolicy.SLOW_ONLY || !slow && policy == SlowPolicy.FAST_ONLY) {
                result.add(aClass);
            }
        }
    }
    return result.toArray(ArrayUtil.EMPTY_CLASS_ARRAY);
}
Also used : InitializationError(org.junit.runners.model.InitializationError) TestCaseLoader(com.intellij.TestCaseLoader) IOException(java.io.IOException)

Example 25 with InitializationError

use of org.junit.runners.model.InitializationError in project intellij-community by JetBrains.

the class JUnit46ClassesRequestBuilder method getClassesRequest.

public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods, Class category) {
    boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
    try {
        if (category != null) {
            try {
                Class.forName("org.junit.experimental.categories.Categories");
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Categories are not available");
            }
        }
        Runner suite;
        if (canUseSuiteMethod) {
            try {
                Class.forName("org.junit.experimental.categories.Categories");
                suite = new IdeaSuite48(collectWrappedRunners(classes), suiteName, category);
            } catch (ClassNotFoundException e) {
                suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
            }
        } else {
            final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
            try {
                Class.forName("org.junit.experimental.categories.Categories");
                suite = new IdeaSuite48(builder, classes, suiteName, category);
            } catch (ClassNotFoundException e) {
                suite = new IdeaSuite(builder, classes, suiteName);
            }
        }
        return Request.runner(suite);
    } catch (InitializationError e) {
        throw new RuntimeException(e);
    }
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) Runner(org.junit.runner.Runner) AllDefaultPossibilitiesBuilder(org.junit.internal.builders.AllDefaultPossibilitiesBuilder) InitializationError(org.junit.runners.model.InitializationError)

Aggregations

InitializationError (org.junit.runners.model.InitializationError)42 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)9 Runner (org.junit.runner.Runner)7 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)5 Field (java.lang.reflect.Field)4 Method (java.lang.reflect.Method)4 JUnitCore (org.junit.runner.JUnitCore)4 RunNotifier (org.junit.runner.notification.RunNotifier)4 File (java.io.File)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 CucumberScenario (cucumber.runtime.model.CucumberScenario)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 Test (org.junit.Test)2 AllDefaultPossibilitiesBuilder (org.junit.internal.builders.AllDefaultPossibilitiesBuilder)2 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)2 ParentRunner (org.junit.runners.ParentRunner)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2