title: Why is Mockito.verify failing a different test than the one I placed it in?
body: <p>Currently developing unit tests for one of my employer's internal Java projects.</p>
  
  <p>While I have extensive unit testing experience has been on the SFDC Apex platform, my background in Java is rather more limited and I'm still wrapping my head around the use of libraries such as Mockito.</p>
  
  <p>At present, I'm being stumped by a very strange test failure involving the use of Mockito.verify.  It is very strange because verify seems to be working as expected, but including it causes a different test to fail.</p>
  
  <p>More specifically, I have these two test methods:</p>
  
  <pre><code>    /**
   * Test of getWindowSize method, of class DefaultWindowHandler.
   */
  @Test
  public void testGetWindowSize() {
      System.out.println("getWindowSize");
      // GIVEN
      final WebDriver mockWebDriver = mock(WebDriver.class);
      final DefaultWindowHandler defaultWindowHandlerUnderTestInstance = new DefaultWindowHandler(mockWebDriver);
      Options mockOptions = mock(Options.class);
      Window mockWindow = mock(Window.class);
      Dimension dummyDimension = new Dimension(1, 2);
  
      // WHEN
      when(mockWebDriver.manage()).thenReturn(mockOptions);
      when(mockOptions.window()).thenReturn(mockWindow);
      when(mockWindow.getSize()).thenReturn(dummyDimension);
  
      final Dimension result = defaultWindowHandlerUnderTestInstance.getWindowSize();
      // THEN
      assertEquals(dummyDimension, result);
  }
  
  /**
   * Test of maximizeWindow method, of class DefaultWindowHandler.
   */
  @Test
  public void testMaximizeWindow() {
      System.out.println("maximizeWindow");
      // GIVEN
      final WebDriver mockWebDriver = mock(WebDriver.class);
      final DefaultWindowHandler defaultWindowHandlerUnderTestInstance = new DefaultWindowHandler(mockWebDriver);
      Options mockOptions = mock(Options.class);
      Window mockWindow = mock(Window.class);
  
      // WHEN
      when(mockWebDriver.manage()).thenReturn(mockOptions);
      when(mockOptions.window()).thenReturn(mockWindow);
  
      defaultWindowHandlerUnderTestInstance.maximizeWindow();
  
      // THEN
      // FIXME: If this is not commented out, a testGetWindowSize will fail!
      //Mockito.verify(mockWindow);
  }
  </code></pre>
  
  <p>As the code currently stands, with <code>"Mockito.verify(mockWindow);"</code> commented out, both tests will pass.</p>
  
  <p>If I remove the <code>//</code> comment marks and allow the verification to occur, the second method, <code>testMaximizeWindow()</code>,  which contains the verification, will pass as expected.  </p>
  
  <p><em>HOWEVER</em>, the first method, <code>testGetWindowSize()</code>, will now fail with an <code>org.mockito.exceptions.misusing.UnfinishedVerificationException</code>. and then go on to indicate this Mockito.verify() within the <code>testMaximizeWindow()</code> method.</p>
  
  <p>Any ideas how I am misusing <code>verify()</code> or what I need to do to "finish" it?</p>