lucian.marcuta
lucian.marcuta

Reputation: 1260

Mockito: verifify invocation with a argument of a given class

I need to write the following assert statement:

verify(tp, never()).addEvent(eventOfTypeA);

It should fail when addEvent is invoked, but only if it is invoked only with a TypeAEvent as parameter. I also tried:

verify(tp, never()).addEvent((TypeAEvent) any());

but it doesn't work.

I know that that I can set a captor, get all events given as parameters and then check each of them using instanceOf(), but I think that is an ugly solution. Any ideas?

Upvotes: 0

Views: 42

Answers (2)

shubham misra
shubham misra

Reputation: 31

Try using

verify(tp, never()).addEvent(Matchers.any(TypeAEvent.class));

Upvotes: 0

Frank
Frank

Reputation: 2066

You could try

verify(tp, never()).addEvent(isA(TypeAEvent.class);

Upvotes: 2

Related Questions