Mock static method

Mock static Class:   

 
byte[] a = {};
SetReader exp = new SetReader();

PowerMock.mockStatic(SetReader.class);       
EasyMock.expect(SetReader.parseFrom(EasyMock.aryEq(a))).andReturn(exp);
PowerMock.replay(SetReader.class);
       
PowerMock.verify(SetReader.class);

 

refer to:  http://code.google.com/p/powermock/wiki/MockStatic

 

  1. Use the @RunWith(PowerMockRunner.class) annotation at the class-level of the test case.
  2. Use the @PrepareForTest(ClassThatContainsStaticMethod.class) annotation at the class-level of the test case.
  3. Use PowerMock.mockStatic(ClassThatContainsStaticMethod.class) to mock all methods of this class.
  4. Use PowerMock.replay(ClassThatContainsStaticMethod.class) to change the class to replay mode.
  5. Use PowerMock.verify(ClassThatContainsStaticMethod.class) to change the class to verify mode.

你可能感兴趣的:(static)