Search in sources :

Example 51 with TestClass

use of org.junit.runners.model.TestClass in project hazelcast by hazelcast.

the class AbstractHazelcastClassRunner method getTestRules.

@Override
protected List<TestRule> getTestRules(Object target) {
    List<TestRule> testRules = super.getTestRules(target);
    Set<Class<? extends TestRule>> testRuleClasses = new HashSet<Class<? extends TestRule>>();
    TestClass testClass = getTestClass();
    // find the required test rule classes from test class itself
    Annotation[] classAnnotations = testClass.getAnnotations();
    for (Annotation annotation : classAnnotations) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
        if (autoFilterRule != null) {
            Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
            testRuleClasses.add(testRuleClass);
        }
    }
    // find the required test rule classes from methods
    List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods();
    for (FrameworkMethod annotatedMethod : annotatedMethods) {
        Annotation[] methodAnnotations = annotatedMethod.getAnnotations();
        for (Annotation annotation : methodAnnotations) {
            Class<? extends Annotation> annotationType = annotation.annotationType();
            AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
            if (autoFilterRule != null) {
                Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
                testRuleClasses.add(testRuleClass);
            }
        }
    }
    // create and register test rules
    for (Class<? extends TestRule> testRuleClass : testRuleClasses) {
        try {
            TestRule testRule = testRuleClass.newInstance();
            testRules.add(testRule);
        } catch (Throwable t) {
            System.err.println("Unable to create test rule instance of test rule class " + testRuleClass.getName() + " because of " + t);
        }
    }
    return testRules;
}
Also used : TestClass(org.junit.runners.model.TestClass) Annotation(java.lang.annotation.Annotation) TestRule(org.junit.rules.TestRule) TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod) HashSet(java.util.HashSet)

Example 52 with TestClass

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

the class GuiTestRunner method loadClassesWithIdeClassLoader.

private void loadClassesWithIdeClassLoader() throws Exception {
    ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
    Thread.currentThread().setContextClassLoader(ideClassLoader);
    Class<?> testClass = getTestClass().getJavaClass();
    myTestClass = new TestClass(ideClassLoader.loadClass(testClass.getName()));
}
Also used : PluginClassLoader(com.intellij.ide.plugins.cl.PluginClassLoader) TestClass(org.junit.runners.model.TestClass)

Example 53 with TestClass

use of org.junit.runners.model.TestClass in project robolectric by robolectric.

the class SandboxTestRunner method invokeBeforeClass.

private void invokeBeforeClass(final Class clazz) throws Throwable {
    if (!loadedTestClasses.contains(clazz)) {
        loadedTestClasses.add(clazz);
        final TestClass testClass = new TestClass(clazz);
        final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeClass.class);
        for (FrameworkMethod before : befores) {
            before.invokeExplosively(null);
        }
    }
}
Also used : TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 54 with TestClass

use of org.junit.runners.model.TestClass in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method getAnnotatedFieldValues.

/*
   * We're using JUnit infrastructure here, but provide constant 
   * ordering of the result. The returned list has class...super order.
   */
private <T> List<T> getAnnotatedFieldValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) {
    TestClass info = AccessController.doPrivileged(new PrivilegedAction<TestClass>() {

        @Override
        public TestClass run() {
            return new TestClass(suiteClass);
        }
    });
    List<T> results = new ArrayList<T>();
    List<FrameworkField> annotatedFields = new ArrayList<FrameworkField>(info.getAnnotatedFields(annotationClass));
    // Split fields by class
    final HashMap<Class<?>, List<FrameworkField>> byClass = new HashMap<Class<?>, List<FrameworkField>>();
    for (FrameworkField field : annotatedFields) {
        Class<?> clz = field.getField().getDeclaringClass();
        if (!byClass.containsKey(clz)) {
            byClass.put(clz, new ArrayList<FrameworkField>());
        }
        byClass.get(clz).add(field);
    }
    // Consistent order at class level.
    for (List<FrameworkField> fields : byClass.values()) {
        Collections.sort(fields, new Comparator<FrameworkField>() {

            @Override
            public int compare(FrameworkField o1, FrameworkField o2) {
                return o1.getField().getName().compareTo(o2.getField().getName());
            }
        });
        Collections.shuffle(fields, new Random(runnerRandomness.getSeed()));
    }
    annotatedFields.clear();
    for (Class<?> clz = suiteClass; clz != null; clz = clz.getSuperclass()) {
        List<FrameworkField> clzFields = byClass.get(clz);
        if (clzFields != null) {
            annotatedFields.addAll(clzFields);
        }
    }
    for (FrameworkField each : annotatedFields) {
        try {
            Object fieldValue = each.get(test);
            if (valueClass.isInstance(fieldValue))
                results.add(valueClass.cast(fieldValue));
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    return results;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) TestClass(org.junit.runners.model.TestClass) Random(java.util.Random) TestClass(org.junit.runners.model.TestClass) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) List(java.util.List) ArrayList(java.util.ArrayList) FrameworkField(org.junit.runners.model.FrameworkField)

Example 55 with TestClass

use of org.junit.runners.model.TestClass in project deltaspike by apache.

the class MyFacesContainerAdapter method boot.

public void boot() {
    final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    this.mockedMyFacesTestContainer = new MyFacesContainer(new TestClass(this.testClass)) {

        @Override
        protected String getWebappResourcePath() {
            TestConfig testConfig = testClass.getJavaClass().getAnnotation(TestConfig.class);
            if (testConfig == null || DEFAULT_TEST_CONFIG_LITERAL.webappResourcePath().equals(testConfig.webappResourcePath())) {
                return MyFacesTestBaseConfig.WEBAPP_RESOURCE_PATH;
            }
            return testConfig.webappResourcePath();
        }

        @Override
        protected void setUpServletObjects() {
            //just needed for MyFaces-Test util v1.0.7
            //(to bypass issues with the outdated URLClassLoader used by AbstractJsfTestContainer)
            setCurrentClassLoader(originalClassLoader);
            super.setUpServletObjects();
        }

        @Override
        protected void setUpWebConfigParams() {
            servletContext.addInitParameter("org.apache.myfaces.config.annotation.LifecycleProvider", "org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider");
            servletContext.addInitParameter("org.apache.myfaces.CHECKED_VIEWID_CACHE_ENABLED", "false");
            servletContext.addInitParameter(ExpressionFactory.class.getName(), "org.apache.el.ExpressionFactoryImpl");
            super.setUpWebConfigParams();
            initContainerConfig();
            //add custom values (might replace the default values)
            for (Map.Entry<String, String> entry : containerConfig.entrySet()) {
                servletContext.addInitParameter(entry.getKey(), entry.getValue());
            }
        }
    };
    this.mockedMyFacesTestContainer.setUp(new Object());
}
Also used : TestConfig(org.apache.myfaces.mc.test.core.annotation.TestConfig) MyFacesContainer(org.apache.myfaces.mc.test.core.runner.MyFacesContainer) TestClass(org.junit.runners.model.TestClass)

Aggregations

TestClass (org.junit.runners.model.TestClass)60 Test (org.junit.Test)41 FrameworkMethod (org.junit.runners.model.FrameworkMethod)12 PotentialAssignment (org.junit.experimental.theories.PotentialAssignment)6 SpecificDataPointsSupplier (org.junit.experimental.theories.internal.SpecificDataPointsSupplier)6 Annotation (java.lang.annotation.Annotation)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PluginClassLoader (com.intellij.ide.plugins.cl.PluginClassLoader)2 HashMap (java.util.HashMap)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 Interaction (au.com.dius.pact.model.Interaction)1 Pact (au.com.dius.pact.model.Pact)1 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)1 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)1 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)1 Provider (au.com.dius.pact.provider.junit.Provider)1