vendredi 28 août 2015

Mock a final method with PowerMock + EasyMock + JUnit 3

I've already searched in SO similar question..so that's why I'm asking from scratch....

I have a class, A, with some final instance methods. From another class, B, in B.instance.method I'm using the A instance final methods.

How can I mock the A instance final methods ? The problem is that after creating the mock with the PowerMock.createMock(A.class), when I should use the PowerMock.expect(...).andReturn(...) I can't use that method, since the only methods available are

  • PowerMock.expectLastCall()
  • PowerMock.expectNew(...)
  • PowerMock.expectPrivate(...)
  • PowerMock.expectStrinctNew(...)

Until now, I've followed the PowerMock tutorial, and I've made the following code run with some exception

@RunWith(PowerMockRunner.class)
@PrepareForTest(A.class)
class Test {

@Test
testMethod {
A Aobj = PowerMock.createMock(A.class);
PowerMock.expect... **====> that's the problem..I don't have the simple expect() but only those listed before**
PowerMock.expectLastCall().anyTimes();
PowerMock.replay(Aobj);
}

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire