title: How to test Spring @EventListener method?
body: <p>I have some event publishing:</p>
  
  <pre><code>@Autowired private final ApplicationEventPublisher publisher;
  ...
  publisher.publishEvent(new MyApplicationEvent(mySource));
  </code></pre>
  
  <p>I have this event listener:</p>
  
  <pre><code>class MyApplicationEventHandler {
  
      @Autowired SomeDependency someDependency;
  
      @EventListener public void processEvent(final MyApplicationEvent event) {
          // handle event...
      }
  }
  </code></pre>
  
  <p>I need to test it using EasyMock. Is there a simple way to publish something in test and assert that my event listener did something?</p>
  
  <p>EDIT:</p>
  
  <p>I tried to create mock test like this:</p>
  
  <pre><code>// testing class
  SomeDependency someDependency = mock(SomeDependency.class);
  
  MyApplicationEventHandler tested = new MyApplicationEventHandler(someDependency);
  
  @Autowired private final ApplicationEventPublisher publisher;
  
  @Test
  public void test() {
      someDependency.doSomething(anyObject(SomeClass.class));
      replay();
      publisher.publishEvent(new MyApplicationEvent(createMySource()));
  }
  </code></pre>
  
  <p>It didn't work.</p>
  
  <pre><code>java.lang.AssertionError: 
    Expectation failure on verify:
      SomeDependency.doSomething(&lt;any&gt;): expected: 1, actual: 0
  </code></pre>