Search in sources :

Example 1 with TestClassTransformer

use of org.powermock.core.transformers.impl.TestClassTransformer in project powermock by powermock.

the class AbstractCommonTestSuiteChunkerImpl method putMethodToChunk.

private void putMethodToChunk(TestCaseEntry testCaseEntry, Class<?> testClass, Method method) {
    if (shouldExecuteTestForMethod(testClass, method)) {
        currentTestIndex++;
        if (hasChunkAnnotation(method)) {
            LinkedList<Method> methodsInThisChunk = new LinkedList<Method>();
            methodsInThisChunk.add(method);
            final String[] staticSuppressionClasses = getStaticSuppressionClasses(testClass, method);
            TestClassTransformer[] extraTransformers = null == testMethodAnnotation() ? new TestClassTransformer[0] : new TestClassTransformer[] { TestClassTransformer.forTestClass(testClass).removesTestMethodAnnotation(testMethodAnnotation()).fromAllMethodsExcept(method) };
            final ClassLoader mockClassloader;
            if (method.isAnnotationPresent(PrepareEverythingForTest.class)) {
                mockClassloader = createNewClassloader(testClass, new String[] { MockClassLoader.MODIFY_ALL_CLASSES }, ignorePackagesExtractor.getPackagesToIgnore(testClass), extraTransformers);
            } else {
                mockClassloader = createNewClassloader(testClass, arrayMerger.mergeArrays(String.class, prepareForTestExtractor.getTestClasses(method), staticSuppressionClasses), ignorePackagesExtractor.getPackagesToIgnore(testClass), extraTransformers);
            }
            TestChunkImpl chunk = new TestChunkImpl(mockClassloader, methodsInThisChunk);
            testCaseEntry.getTestChunks().add(chunk);
            updatedIndexes();
        } else {
            testCaseEntry.getTestChunks().get(0).getTestMethodsToBeExecutedByThisClassloader().add(method);
            // currentClassloaderMethods.add(method);
            final int currentDelegateIndex = internalSuites.size() - 1;
            /*
                 * Add this test index to the main junit runner
                 * delegator.
                 */
            List<Integer> testList = testAtDelegateMapper.get(currentDelegateIndex);
            if (testList == null) {
                testList = new LinkedList<Integer>();
                testAtDelegateMapper.put(currentDelegateIndex, testList);
            }
            testList.add(currentTestIndex);
        }
    }
}
Also used : Method(java.lang.reflect.Method) TestClassTransformer(org.powermock.core.transformers.impl.TestClassTransformer) LinkedList(java.util.LinkedList) MockClassLoader(org.powermock.core.classloader.MockClassLoader)

Aggregations

Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 MockClassLoader (org.powermock.core.classloader.MockClassLoader)1 TestClassTransformer (org.powermock.core.transformers.impl.TestClassTransformer)1