title: Mockito: How to verify a method was called only once with exact parameters ignoring calls to other methods?
body: <p>Using Mockito in Java how to verify a method was called only once with exact parameters ignoring calls to other methods?</p>
  
  <p>Sample code:</p>
  
  <pre><code>public class MockitoTest {
  
      interface Foo {
          void add(String str);
          void clear();
      }
  
  
      @Test
      public void testAddWasCalledOnceWith1IgnoringAllOtherInvocations() throws Exception {
          // given
          Foo foo = Mockito.mock(Foo.class);
  
          // when
          foo.add("1"); // call to verify
          foo.add("2"); // !!! don't allow any other calls to add()
          foo.clear();  // calls to other methods should be ignored
  
          // then
          Mockito.verify(foo, Mockito.times(1)).add("1");
          // TODO: don't allow all other invocations with add() 
          //       but ignore all other calls (i.e. the call to clear())
      }
  
  }
  </code></pre>
  
  <p>What should be done in the <code>TODO: don't allow all other invocations with add()</code> section?</p>
  
  <p>Already unsuccessfully tried:</p>
  
  <ol>
  <li><code>verifyNoMoreInteractions(foo);</code></li>
  </ol>
  
  <p>Nope. It does not allow calls to other methods like <code>clear()</code>.</p>
  
  <ol start="2">
  <li><code>verify(foo, times(0)).add(any());</code></li>
  </ol>
  
  <p>Nope. It does not take into account that we allow one call to <code>add("1")</code>.</p>