org.powermock.tests.utils.impl
Class AbstractTestSuiteChunkerImpl<T>

java.lang.Object
  extended by org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl<T>
All Implemented Interfaces:
TestSuiteChunker

public abstract class AbstractTestSuiteChunkerImpl<T>
extends Object
implements TestSuiteChunker

Abstract base class for test suite chunking, i.e. a suite is chunked into several smaller pieces which are ran with different classloaders. A chunk is defined by the PrepareForTest annotation. This to make sure that you can byte-code manipulate classes in tests without impacting on other tests.


Field Summary
protected  List<T> delegates
           
protected  Set<Class<?>> delegatesCreatedForTheseClasses
           
protected static int NOT_INITIALIZED
           
protected  TestClassesExtractor prepareForTestExtractor
           
protected  TestClassesExtractor suppressionExtractor
           
protected  LinkedHashMap<Integer,List<Integer>> testAtDelegateMapper
           
protected  int testCount
           
 
Constructor Summary
protected AbstractTestSuiteChunkerImpl(Class<?>... testClasses)
           
protected AbstractTestSuiteChunkerImpl(Class<?> testClass)
           
 
Method Summary
protected  void chunkClass(Class<?> testClass)
           
protected abstract  T createDelegatorFromClassloader(ClassLoader classLoader, Class<?> testClass, List<Method> methodsToTest)
           
 ClassLoader createNewClassloader(Class<?> testClass, String[] classesToLoadByMockClassloader, String[] packagesToIgnore)
          Create a new class loader and load classes from this classloader.
 void createTestDelegators(Class<?> testClass, List<TestChunk> chunks)
          Create the test delegators needed for a whole class.
 int getChunkSize()
          Get the number of chunks defined in this suite.
 int getDelegatorIndex(int testIndex)
          Get the junit runner delegate that handles the test at index testIndex.
 int getInternalTestIndex(int originalTestIndex)
          Get the internal test index for a junit runner delegate based on the "real" original test index.
protected  Object getPowerMockTestListenersLoadedByASpecificClassLoader(Class<?> clazz, ClassLoader classLoader)
           
 List<TestChunk> getTestChunks()
          Get all chunk entries.
 List<TestChunk> getTestChunksEntries(Class<?> testClass)
          Get all chunk entries for a specific class.
 Class<?>[] getTestClasses()
           
protected  boolean hasMockPolicyProvidedClasses(Class<?> testClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.powermock.tests.utils.TestSuiteChunker
getTestCount, shouldExecuteTestForMethod
 

Field Detail

NOT_INITIALIZED

protected static final int NOT_INITIALIZED
See Also:
Constant Field Values

prepareForTestExtractor

protected final TestClassesExtractor prepareForTestExtractor

suppressionExtractor

protected final TestClassesExtractor suppressionExtractor

delegatesCreatedForTheseClasses

protected final Set<Class<?>> delegatesCreatedForTheseClasses

delegates

protected final List<T> delegates

testAtDelegateMapper

protected final LinkedHashMap<Integer,List<Integer>> testAtDelegateMapper

testCount

protected volatile int testCount
Constructor Detail

AbstractTestSuiteChunkerImpl

protected AbstractTestSuiteChunkerImpl(Class<?> testClass)
                                throws Exception
Throws:
Exception

AbstractTestSuiteChunkerImpl

protected AbstractTestSuiteChunkerImpl(Class<?>... testClasses)
                                throws Exception
Throws:
Exception
Method Detail

getPowerMockTestListenersLoadedByASpecificClassLoader

protected Object getPowerMockTestListenersLoadedByASpecificClassLoader(Class<?> clazz,
                                                                       ClassLoader classLoader)

chunkClass

protected void chunkClass(Class<?> testClass)
                   throws Exception
Throws:
Exception

createNewClassloader

public ClassLoader createNewClassloader(Class<?> testClass,
                                        String[] classesToLoadByMockClassloader,
                                        String[] packagesToIgnore)
Description copied from interface: TestSuiteChunker
Create a new class loader and load classes from this classloader.

Specified by:
createNewClassloader in interface TestSuiteChunker
Parameters:
testClass - TODO
classesToLoadByMockClassloader - An array of the fully qualified name of the classes to modify.
packagesToIgnore - Packages to ignore.

createTestDelegators

public void createTestDelegators(Class<?> testClass,
                                 List<TestChunk> chunks)
                          throws Exception
Create the test delegators needed for a whole class.

Specified by:
createTestDelegators in interface TestSuiteChunker
Throws:
Exception

createDelegatorFromClassloader

protected abstract T createDelegatorFromClassloader(ClassLoader classLoader,
                                                    Class<?> testClass,
                                                    List<Method> methodsToTest)
                                             throws Exception
Throws:
Exception

getChunkSize

public int getChunkSize()
Description copied from interface: TestSuiteChunker
Get the number of chunks defined in this suite.

Specified by:
getChunkSize in interface TestSuiteChunker
Returns:
The number of chunks defined in the correct suite.

getTestChunks

public List<TestChunk> getTestChunks()
Description copied from interface: TestSuiteChunker
Get all chunk entries.

Specified by:
getTestChunks in interface TestSuiteChunker
Returns:
An set of entries that contains a list of methods contained in the chunk and the class loader that loaded these methods.

getInternalTestIndex

public int getInternalTestIndex(int originalTestIndex)
Get the internal test index for a junit runner delegate based on the "real" original test index. For example, the test may need to run a single test, for example the test with index 3. However since PowerMock may have chunked the test suite to use many classloaders and junit delegators the index (3) must be mapped to an internal representation for the specific junit runner delegate. This is what this method does. I.e. it will iterate through all junit runner delegates and see if they contain the test with index 3, in the internal index of this test delegator is returned.

Parameters:
originalTestIndex - The original test index as seen by the test runner.
Returns:
The internal test index as seen by PowerMock or -1 if no index was found.

getDelegatorIndex

public int getDelegatorIndex(int testIndex)
Get the junit runner delegate that handles the test at index testIndex. Throws a RuntimeException if a delegator is not found for the specific test index.

Parameters:
testIndex - The test index that a delegator should hold.
Returns:
The index for of the junit runner delegate as seen by JTestRack.

getTestChunksEntries

public List<TestChunk> getTestChunksEntries(Class<?> testClass)
Get all chunk entries for a specific class.

Specified by:
getTestChunksEntries in interface TestSuiteChunker
Parameters:
testClass - The class whose chunk entries to get.
Returns:
An set of entries that contains a list of methods contained in the chunk for the specific test class and the class loader that loaded these methods.

getTestClasses

public Class<?>[] getTestClasses()

hasMockPolicyProvidedClasses

protected boolean hasMockPolicyProvidedClasses(Class<?> testClass)
Returns:
true if there are some mock policies that contributes with classes that should be loaded by the mock classloader, false otherwise.


Copyright © 2007-2014. All Rights Reserved.