Search in sources :

Example 1 with PowerMockJUnit3RunnerDelegate

use of org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate in project powermock by powermock.

the class JUnit3TestSuiteChunkerImpl method runTest.

public void runTest(Test test, TestResult result) {
    final Iterator<TestChunk> iterator = getChunkIterator();
    for (PowerMockJUnit3RunnerDelegate delegate : delegates) {
        TestChunk next = iterator.next();
        final PowerMockJUnit3TestListener listener = new PowerMockJUnit3TestListener(next.getClassLoader());
        result.addListener(listener);
        delegate.runTest(test, result);
        result.removeListener(listener);
    }
}
Also used : TestChunk(org.powermock.tests.utils.TestChunk) PowerMockJUnit3RunnerDelegate(org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate)

Example 2 with PowerMockJUnit3RunnerDelegate

use of org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate in project powermock by powermock.

the class JUnit3TestSuiteChunkerImpl method tests.

public Enumeration<?> tests() {
    final List<Object> tests = new LinkedList<Object>();
    for (PowerMockJUnit3RunnerDelegate delegate : delegates) {
        final Enumeration<?> delegateTests = delegate.tests();
        while (delegateTests.hasMoreElements()) {
            tests.add(delegateTests.nextElement());
        }
    }
    Enumeration<?> allTests = new Enumeration<Object>() {

        private volatile int count = 0;

        public boolean hasMoreElements() {
            return count != tests.size();
        }

        public Object nextElement() {
            return tests.get(count++);
        }
    };
    return allTests;
}
Also used : Enumeration(java.util.Enumeration) PowerMockJUnit3RunnerDelegate(org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate) LinkedList(java.util.LinkedList)

Example 3 with PowerMockJUnit3RunnerDelegate

use of org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate in project powermock by powermock.

the class JUnit3TestSuiteChunkerImpl method createDelegatorFromClassloader.

@Override
protected PowerMockJUnit3RunnerDelegate createDelegatorFromClassloader(ClassLoader classLoader, Class<?> testClass, final List<Method> methodsToTest) throws Exception {
    final Class<?> testClassLoadedByMockedClassLoader = Class.forName(testClass.getName(), false, classLoader);
    final Class<?> powerMockTestListenerArrayType = Class.forName(PowerMockTestListener[].class.getName(), false, classLoader);
    Class<?> delegateClass = Class.forName(PowerMockJUnit3RunnerDelegateImpl.class.getName(), false, classLoader);
    Constructor<?> con = delegateClass.getConstructor(Class.class, Method[].class, powerMockTestListenerArrayType);
    final PowerMockJUnit3RunnerDelegate newDelegate = (PowerMockJUnit3RunnerDelegate) con.newInstance(testClassLoadedByMockedClassLoader, methodsToTest.toArray(new Method[0]), getPowerMockTestListenersLoadedByASpecificClassLoader(testClass, classLoader));
    newDelegate.setName(name);
    return newDelegate;
}
Also used : Method(java.lang.reflect.Method) PowerMockJUnit3RunnerDelegate(org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate)

Example 4 with PowerMockJUnit3RunnerDelegate

use of org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate in project powermock by powermock.

the class JUnit3TestSuiteChunkerImpl method run.

public void run(TestResult result) {
    final Iterator<TestChunk> iterator = getChunkIterator();
    for (PowerMockJUnit3RunnerDelegate delegate : delegates) {
        TestChunk next = iterator.next();
        final PowerMockJUnit3TestListener listener = new PowerMockJUnit3TestListener(next.getClassLoader());
        result.addListener(listener);
        // Initialize mock policies for each test
        new MockPolicyInitializerImpl(delegate.getTestClass()).initialize(this.getClass().getClassLoader());
        delegate.run(result);
        result.removeListener(listener);
    }
}
Also used : TestChunk(org.powermock.tests.utils.TestChunk) PowerMockJUnit3RunnerDelegate(org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate) MockPolicyInitializerImpl(org.powermock.tests.utils.impl.MockPolicyInitializerImpl)

Aggregations

PowerMockJUnit3RunnerDelegate (org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate)4 TestChunk (org.powermock.tests.utils.TestChunk)2 Method (java.lang.reflect.Method)1 Enumeration (java.util.Enumeration)1 LinkedList (java.util.LinkedList)1 MockPolicyInitializerImpl (org.powermock.tests.utils.impl.MockPolicyInitializerImpl)1