Search in sources :

Example 1 with MockPolicyInitializerImpl

use of org.powermock.tests.utils.impl.MockPolicyInitializerImpl in project powermock by powermock.

the class PowerMockJUnit4LegacyRunnerDelegateImpl method run.

@Override
public void run(final RunNotifier notifier) {
    BeforeAndAfterRunner runner = new BeforeAndAfterRunner(getTestClass(), BeforeClass.class, AfterClass.class, null) {

        @Override
        protected void runUnprotected() {
            fEnclosedRunner.run(notifier);
        }

        @Override
        protected void addFailure(Throwable targetException) {
            notifier.fireTestFailure(new Failure(getDescription(), targetException));
        }
    };
    Whitebox.setInternalState(runner, "fTestIntrospector", new PowerMockJUnit4LegacyTestIntrospector(getTestClass()), BeforeAndAfterRunner.class);
    // Initialize mock policies for each test
    final ClassLoader classLoader = this.getClass().getClassLoader();
    new MockPolicyInitializerImpl(getTestClass()).initialize(classLoader);
    Thread.currentThread().setContextClassLoader(classLoader);
    runner.runProtected();
}
Also used : BeforeAndAfterRunner(org.junit.internal.runners.BeforeAndAfterRunner) PowerMockJUnit4LegacyTestIntrospector(org.powermock.modules.junit4.legacy.internal.impl.testcaseworkaround.PowerMockJUnit4LegacyTestIntrospector) MockPolicyInitializerImpl(org.powermock.tests.utils.impl.MockPolicyInitializerImpl) Failure(org.junit.runner.notification.Failure)

Example 2 with MockPolicyInitializerImpl

use of org.powermock.tests.utils.impl.MockPolicyInitializerImpl in project powermock by powermock.

the class PowerMockStatement method init.

protected void init(Object target) {
    final Class<?> testClass = target.getClass();
    try {
        mockPolicyInitializer = new MockPolicyInitializerImpl(testClass);
        testSuiteChunker = new PowerMockRuleTestSuiteChunker(testClass);
        previousTargetClass = target.getClass();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MockPolicyInitializerImpl(org.powermock.tests.utils.impl.MockPolicyInitializerImpl)

Example 3 with MockPolicyInitializerImpl

use of org.powermock.tests.utils.impl.MockPolicyInitializerImpl in project powermock by powermock.

the class PowerMockAgentTestInitializer method initialize.

public static void initialize(Class<?> testClass, JavaAgentClassRegister agentClassRegister) {
    /*
         * For extra safety clear the MockitoRepository.
		 */
    MockRepository.clear();
    redefineClasses(testClass, agentClassRegister);
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    new MockPolicyInitializerImpl(testClass).initialize(contextClassLoader);
}
Also used : MockPolicyInitializerImpl(org.powermock.tests.utils.impl.MockPolicyInitializerImpl)

Example 4 with MockPolicyInitializerImpl

use of org.powermock.tests.utils.impl.MockPolicyInitializerImpl 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

MockPolicyInitializerImpl (org.powermock.tests.utils.impl.MockPolicyInitializerImpl)4 BeforeAndAfterRunner (org.junit.internal.runners.BeforeAndAfterRunner)1 Failure (org.junit.runner.notification.Failure)1 PowerMockJUnit3RunnerDelegate (org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate)1 PowerMockJUnit4LegacyTestIntrospector (org.powermock.modules.junit4.legacy.internal.impl.testcaseworkaround.PowerMockJUnit4LegacyTestIntrospector)1 TestChunk (org.powermock.tests.utils.TestChunk)1