title: Mockito specific matchers like anyString() don't seem to work with overloaded methods?
body: <p>I'm attempting to write a unit test for a class with JUnit and Mockito and in my testing, I've found that a method that I'm trying to stub is actually overloaded and has two definitions, one with 3 strings as an arg and returns an object, another with four strings and returns a list of the aforementioned object. I'm curious as to why matchers such as anyString() don't seem to successfully stub the method, while any() does.</p>
  <p>Is there any way I can get more specific matchers to work, or am I stuck with using any() for overloaded methods?</p>
  <p>An example of what I mean:</p>
  <pre><code>public String testedMethod(String s) {
      //I want to mock this
      return classObject.method(String first, String second, String third);
  }
  </code></pre>
  <pre><code>public class classObject {
      public String method(String first, String second, String third) {
          return &quot;3 args&quot;;
      }
  
      public List&lt;String&gt; method(String first, String second, String third, String fourth) {
          ArrayList&lt;String&gt; returned = new ArrayList&lt;&gt;();
          returned.add(&quot;4 args&quot;);
          return returned;
      }
  }
  </code></pre>
  <pre><code>@Test
  public void testClassMethod() {
      //this doesn't work
      //Mockito.when(classObject).method(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()).thenReturn(&quot;successful stub&quot;);
  
      //this does work
      Mockito.when(classObject).method(Mockito.any(), Mockito.any(), Mockito.any()).thenReturn(&quot;successful stub&quot;);
  
      //only passes with the second mock
      Assert.assertEquals(&quot;successful stub&quot;, testedClass.testedMethod(&quot;a string&quot;));
  }
  </code></pre>