Search in sources :

Example 56 with TestClass

use of org.junit.runners.model.TestClass in project alchemy-test by SirWellington.

the class TestClassInjectorsTest method testPopulateGeneratedFieldsWithBadList.

@Test
public void testPopulateGeneratedFieldsWithBadList() throws Exception {
    System.out.println("testPopulateGeneratedFieldsWithBadList");
    TestClass testClass = new TestClass(BadListTest.class);
    BadListTest instance = new BadListTest();
    assertThrows(() -> TestClassInjectors.populateGeneratedFields(testClass, instance)).isInstanceOf(IllegalArgumentException.class);
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest)

Example 57 with TestClass

use of org.junit.runners.model.TestClass in project alchemy-test by SirWellington.

the class AlchemyTestRunner method shouldInitMockitoMocks.

private boolean shouldInitMockitoMocks() {
    TestClass testClass = this.getTestClass();
    InitMocks initMocks = testClass.getAnnotation(InitMocks.class);
    if (initMocks != null) {
        return initMocks.value();
    }
    return true;
}
Also used : TestClass(org.junit.runners.model.TestClass)

Example 58 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)

Example 59 with TestClass

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

the class PerTestClassLoaderRunner method loadClassesWithCustomClassLoader.

/**
   * Load classes (TestCase, @Before and @After with custom class loader.
   *
   * @throws ClassNotFoundException the class not found exception
   */
private void loadClassesWithCustomClassLoader() throws ClassNotFoundException {
    String classPath = System.getProperty("java.class.path");
    StringTokenizer st = new StringTokenizer(classPath, ":");
    List<URL> urls = new ArrayList<URL>();
    while (st.hasMoreTokens()) {
        String u = st.nextToken();
        try {
            if (!u.endsWith(".jar")) {
                u += "/";
            }
            URL url = new URL("file://" + u);
            urls.add(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    ClassLoader classLoader = new ChildFirstClassLoader(urls.toArray(new URL[] {}), Thread.currentThread().getContextClassLoader());
    Thread.currentThread().setContextClassLoader(classLoader);
    testClassFromClassLoader = new TestClass(classLoader.loadClass(getTestClass().getJavaClass().getName()));
    // See withAfters and withBefores for the reason.
    beforeFromClassLoader = classLoader.loadClass(Before.class.getName());
    afterFromClassLoader = classLoader.loadClass(After.class.getName());
    ruleFromClassLoader = classLoader.loadClass(Rule.class.getName());
    testRuleFromClassLoader = classLoader.loadClass(TestRule.class.getName());
    methodRuleFromClassLoader = classLoader.loadClass(MethodRule.class.getName());
}
Also used : StringTokenizer(java.util.StringTokenizer) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) TestClass(org.junit.runners.model.TestClass) URL(java.net.URL)

Example 60 with TestClass

use of org.junit.runners.model.TestClass in project ddf by codice.

the class PaxExamRule method finished.

private void finished(Description description) {
    LOGGER.info("Finished {} ({}/{})", description.getMethodName(), testsExecuted, testCount);
    if (testsExecuted == testCount) {
        resetStaticFields();
        String testClassName = description.getTestClass().getSimpleName();
        try {
            runAnnotations(AfterExam.class, new TestClass(description.getTestClass()));
        } catch (Throwable throwable) {
            failRule(testClassName, throwable, AFTER_EXAM_FAILURE_MESSAGE);
        }
        LOGGER.info("Finished test(s) for {}", testClassName);
    }
}
Also used : 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