Radu Stoenescu
Radu Stoenescu

Reputation: 3205

Test indirect method invocation using Mockito

I have a method a() that, given the right circumstances should call another method b(). b() does not belong to a mocked object, but a() does. I'm currently trying this:

verify(mockedObject,times(1)).b(); notMocked.a();

It seems that the invocation of b() is not captured by Mockito.

Thanks

Update: I came up with this hack to signal the method invocation, although I not happy at all with it. when(mocked.b()).thenThrow(new ItWasCalledException());

Upvotes: 0

Views: 796

Answers (1)

Radu Stoenescu
Radu Stoenescu

Reputation: 3205

I should have done it in a different order.

notMocked.a(); verify(mockedObject,times(1)).b();

This works like a charm.

Upvotes: 2

Related Questions