use of org.powermock.tests.utils.impl.PowerMockTestNotifierImpl in project powermock by powermock.
the class JUnit4TestSuiteChunkerImpl method run.
@Override
public void run(RunNotifier notifier) {
List<TestChunk> chunkEntries = getTestChunks();
Iterator<TestChunk> iterator = chunkEntries.iterator();
if (delegates.size() != getChunkSize()) {
throw new IllegalStateException("Internal error: There must be an equal number of suites and delegates.");
}
final Class<?> testClass = getTestClasses()[0];
final PowerMockTestListener[] powerMockTestListeners = (PowerMockTestListener[]) getPowerMockTestListenersLoadedByASpecificClassLoader(testClass, this.getClass().getClassLoader());
final Set<Method> allMethods = new LinkedHashSet<Method>();
for (TestChunk testChunk : getTestChunks()) {
allMethods.addAll(testChunk.getTestMethodsToBeExecutedByThisClassloader());
}
final Method[] allMethodsAsArray = allMethods.toArray(new Method[allMethods.size()]);
final PowerMockTestNotifier powerMockTestNotifier = new PowerMockTestNotifierImpl(powerMockTestListeners);
powerMockTestNotifier.notifyBeforeTestSuiteStarted(testClass, allMethodsAsArray);
int failureCount = 0;
int successCount = 0;
int ignoreCount = 0;
for (PowerMockJUnitRunnerDelegate delegate : delegates) {
TestChunk next = iterator.next();
final ClassLoader key = next.getClassLoader();
PowerMockJUnit4RunListener powerMockListener = new PowerMockJUnit4RunListener(key, powerMockTestNotifier);
notifier.addListener(powerMockListener);
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(key);
try {
MockingFrameworkReporter mockingFrameworkReporter = getMockingFrameworkReporter();
mockingFrameworkReporter.enable();
delegate.run(notifier);
mockingFrameworkReporter.disable();
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
final int failureCountForThisPowerMockListener = powerMockListener.getFailureCount();
final int ignoreCountForThisPowerMockListener = powerMockListener.getIgnoreCount();
failureCount += failureCountForThisPowerMockListener;
ignoreCount += ignoreCountForThisPowerMockListener;
successCount += delegate.getTestCount() - failureCountForThisPowerMockListener - ignoreCountForThisPowerMockListener;
notifier.removeListener(powerMockListener);
}
final TestSuiteResult testSuiteResult = new TestSuiteResultImpl(failureCount, successCount, getTestCount(), ignoreCount);
powerMockTestNotifier.notifyAfterTestSuiteEnded(testClass, allMethodsAsArray, testSuiteResult);
}
Aggregations