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();
}
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);
}
}
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);
}
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);
}
}
Aggregations