AbstractCommonTestSuiteChunkerImpl(Class<?>... testClasses) throws Exception { this.testClasses = testClasses; for (Class<?> clazz : testClasses) { chunkClass(clazz); } }
private void findMethods(TestCaseEntry testCaseEntry, Class<?> testClass) { Method[] allMethods = testClass.getMethods(); for (Method method : allMethods) { putMethodToChunk(testCaseEntry, testClass, method); } testClass = testClass.getSuperclass(); if (!Object.class.equals(testClass)) { findMethods(testCaseEntry, testClass); } }
@Override public int getChunkSize() { return getTestChunks().size(); }
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 ClassLoader mockClassloader = createClassLoaderForMethod(testClass, method); updatedIndexes(); } else { testCaseEntry.getTestChunks().get(0).getTestMethodsToBeExecutedByThisClassloader().add(method);
final ClassLoader defaultMockLoader = createDefaultMockLoader(testClass, testMethodsForOtherClassLoaders); initEntries(internalSuites);
private ClassLoader createDefaultMockLoader(final Class<?> testClass, final Collection<Method> testMethodsForOtherClassLoaders) { final MockTransformer extraMockTransformer; if (null == testMethodAnnotation()) { extraMockTransformer = null; } else { extraMockTransformer = TestClassTransformerBuilder .forTestClass(testClass) .removesTestMethodAnnotation(testMethodAnnotation()) .fromMethods(testMethodsForOtherClassLoaders); } return new MockClassLoaderFactory(testClass).createForClass(extraMockTransformer); }
private void initEntries(List<TestCaseEntry> entries) { for (TestCaseEntry testCaseEntry : entries) { final Class<?> testClass = testCaseEntry.getTestClass(); findMethods(testCaseEntry, testClass); } }
private ClassLoader createClassLoaderForMethod(final Class<?> testClass, final Method method) { final MockTransformer extraMockTransformer; if (null == testMethodAnnotation()) { extraMockTransformer = null; } else { extraMockTransformer = TestClassTransformerBuilder.forTestClass(testClass) .bytecodeFrameworkClue(method) .removesTestMethodAnnotation(testMethodAnnotation()) .fromAllMethodsExcept(method); } final MockClassLoaderFactory classLoaderFactory = new MockClassLoaderFactory(testClass); return classLoaderFactory.createForMethod(method, extraMockTransformer); }
public TestChunk getTestChunk(Method method) { for (TestChunk testChunk : getTestChunks()) { if (testChunk.isMethodToBeExecutedByThisClassloader(method)) { return testChunk; } } return null; }