title: How to unit test event firing?
body: <p>Suppose I have an object, that should fire some event on some operation?</p>
  
  <p>How would I test it?</p>
  
  <p>I can add listener to it, but the code of listener will be separated from testing. </p>
  
  <pre><code>final ArrayList&lt;MyEvent&gt; eventsFired = new ArrayList&lt;&gt;();
  myObject.addMyEventListener(new MyEventListener() {
     public void myEventHappened(MyEvent evt) {
        eventsFired.add(evt);
     }
  });
  result = myObject.runOperation();
  assert(result, ...);
  assert(eventsFired.size(), ...); // is by one grater than before operation
  assert(eventsFired.get(eventdFired.size()-1_, ...) // is correct
  </code></pre>
  
  <p>How to get them in one place? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Can I write something like this:</p>
  
  <pre><code>assertThat( myObject.runOperation() ).fires( ... )
  </code></pre>
  
  <p>or something like</p>
  
  <pre><code>Events events = captureEvents( object.runOperation() );
  assertThat( events...)
  </code></pre>