/** * Must be executed before each test method. This method does the following: * <ol> * <li>Injects all mock fields (if they haven't been injected already)</li> * </ol> * * * * @throws Exception * If something unexpected goes wrong. */ @BeforeMethod protected void beforePowerMockTestMethod() throws Exception { injectMocks(); }
@BeforeClass protected void beforePowerMockTestClass() throws Exception { // To make sure that the mock repository is not in an incorrect state when the test begins MockRepository.clear(); if(isLoadedByPowerMockClassloader()) { final Thread thread = Thread.currentThread(); previousCl = thread.getContextClassLoader(); thread.setContextClassLoader(this.getClass().getClassLoader()); } }
/** * Must be executed after each test method. This method does the following: * <ol> * <li>Clear all injection fields (those annotated with a Mock annotation)</li> * <li>Clears the PowerMock MockRepository</li> * </ol> * * @throws Exception if something unexpected goes wrong. */ @AfterMethod protected void afterPowerMockTestMethod() throws Exception { try { clearMockFields(); } finally { MockRepository.clear(); } }