title: Mockito - Match any instance implementing an interface, and answer
body: <p>Mocking a class that at some point is called to add an instance of ActionListener (the interface in java.awt.event) with signature</p>
  
  <pre><code>public void addActionListener(ActionListener l).
  </code></pre>
  
  <p>Trying to mock the method call to use an answer, so that I can keep track of its ActionListeners, when it is called with anonymously created instances of ActionListener (just like in this <a href="https://stackoverflow.com/a/6746257/2245763">answer</a>). But I am unable to make it accept any instance of interface ActionListener.</p>
  
  <p>So far I have tried several examples from other questions, to no avail:</p>
  
  <pre><code>when(mock.addActionListener(Matchers.&lt;ActionListener&gt;any())).thenAnswer(new Answer&lt;Void&gt;() {
          @Override
          public Void answer(InvocationOnMock invocation) throws Throwable {
              Object[] arguments = invocation.getArguments();
              if (arguments != null &amp;&amp; arguments.length &gt; 0 &amp;&amp; arguments[0] != null) {
                  listeners.add((ActionListener) arguments[0]);
              }
              return null;
          }
      });
  when(mock.addActionListener(any(ActionListener.class))).thenAnswer([..snip..]);
  </code></pre>
  
  <p>All of them give compilation errors saying <em>Cannot resolve method when(void)</em>.</p>
  
  <p><strong>Is there any way to make Matchers.any match against any instance that implements the interface, and use it for the answer? Is it not possible because its return value is void?</strong></p>
  
  <p>Using Mockito 1.10, powermock 1.6.5 and java 7. (I can't use Java 8)</p>