power mock 使用 静态方法

阅读更多
引用


1.4.10




junit
junit
4.11



      org.powermock
      powermock-module-junit4
      ${powermock.version}
      test
  

  
      org.powermock
      powermock-api-mockito
      ${powermock.version}
      test
  








@RunWith(PowerMockRunner.class)
@PrepareForTest(ContextManager.class)
public class TestTableDdlSeq {



@Test
	public void testHandlePriorityTables() throws Exception{
		
		PowerMockito.mockStatic(ContextManager.class); 


//TalePriorityDaoImpl impl = spy(new TalePriorityDaoImpl()); //mock(TalePriorityDaoImpl.class);

		//TalePriorityDaoImpl impl = mock(TalePriorityDaoImpl.class);
		
		TablePriorityDaoImpl impl = spy(new TablePriorityDaoImpl());
		
		PowerMockito.when(ContextManager.getReference("tablePriorityDao", TablePriorityDaoImpl.class)).thenReturn(impl);
		PowerMockito.when(impl.getFullName()).thenReturn("123");
		System.out.println(impl.getFullName());


}

你可能感兴趣的:(powermock)