title: MissingMethodInvocationException when calling public non static function on a mock object
body: <p>Im writing a test using Mockito. My class looks like this:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class MailContainsAttachmentJsonFilterTest {
  
      private MailContainsAttachmentJsonFilter mailContainsAttachmentJsonFilter;
      private JavaMailSender javaMailSender;
  
      @Before
          public void setUp() throws Exception {
              mailContainsAttachmentJsonFilter = new MailContainsAttachmentJsonFilter();
          javaMailSender = new JavaMailSenderImpl();
      }
  </code></pre>
  
  <p>And the test:</p>
  
  <pre><code>@Test
  public void filterTest01() throws MessagingException, IOException {
      MimeMessage mimeMessage = Mockito.mock(MimeMessage.class);
      Folder folder = Mockito.mock(Folder.class);
  
      Mockito.when(folder.isOpen()).thenReturn(true);
      Mockito.when(mimeMessage.getFolder()).thenReturn(folder);
  
      MimeMessage message = javaMailSender.createMimeMessage();
      MimeMessageHelper messageHelper = new MimeMessageHelper(message, true);
  
      messageHelper.addAttachment("test.json", new ByteArrayDataSource("{}", "application/json"));
      Mockito.when(mimeMessage).thenReturn(messageHelper.getMimeMessage());
  
      mailContainsAttachmentJsonFilter.filter(mimeMessage);
  }
  </code></pre>
  
  <p>When I run the test, as soon as I reach the <code>Mockito.when(folderisOpen()).thenReturn(true)</code>, I get:</p>
  
  <pre><code>org.mockito.exceptions.misusing.MissingMethodInvocationException: 
  when() requires an argument which has to be 'a method call on a mock'.
  For example:
  when(mock.getArticles()).thenReturn(articles);
  
  Also, this error might show up because:
  1. you stub either of: final/private/equals()/hashCode() methods.
     Those methods *cannot* be stubbed/verified.
     Mocking methods declared on non-public parent classes is not 
  supported.
  2. inside when() you don't call method on mock but on some other 
  object.
  </code></pre>
  
  <p><code>MimeMessage</code> and <code>Folder</code> are both from <code>javax.mail</code>.</p>
  
  <p>As far as I can tell, none of the methods I try to mock, are final/private/equals()/hashcode().</p>