Mockito Test Events

I have a class that emits events, eg.

public class EventSource{
 public addEventListener(EventListener listener).....
 public raiseEvent(){
    Event e=....




I am using Mockito to mock EventListener and want to do equality for an event object (eg event.getTime () .. event.getMessage (), etc.). The event object has no equals method, so I can't easily create another object and do an assert.

What is the normal way to do this with Mockito?


source to share

1 answer

It sounds like you want to use the> argument .

For example:

ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
assertEquals("ExpectedMessage", argument.getValue().getMessage());




All Articles