title: Mockito using argument matchers for when call on method with variable number of arguments
body: <p>I am attempting to use argument matchers inside a when call to a method that has a variable number of arguments (the <code>...</code> thing in Java) without success.  My code is below and I'll also list all of the lines I tried using to make this work.</p>
  
  <pre><code>import static org.mockito.Mockito.*;
  
  public class MethodTest {
      public String tripleDot(String... args) {
          String sum = "";
          for (String i : args) {
              sum += i;
          }
          System.out.println(sum);
  
          return sum;
      }
  
      public static void main(String[] args) {
          try{
              MethodTest mt = mock(MethodTest.class);
              when(mt.tripleDot((String[])anyObject())).thenReturn("Hello world!");
              System.out.println(mt.tripleDot(new String[]{"1","2"}));
          }
          catch (Exception e) {
              System.out.println(e.getClass().toString() + ": " + e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>If print statement is:</p>
  
  <pre><code>System.out.println(mt.tripleDot(new String[]{"1"}));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>System.out.println(mt.tripleDot("1"));
  </code></pre>
  
  <p>It will print "Hello world."</p>
  
  <p>But if the print statement is:</p>
  
  <pre><code>System.out.println(mt.tripleDot(new String[]{"1","2"}));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>System.out.println(mt.tripleDot("1","2"));
  </code></pre>
  
  <p>It will print "null".</p>
  
  <p>I've also tried doing variations in the when call, such as <code>anyObject()</code> or <code>anyString()</code> but to no avail.  I'm not sure if Mockito can handle using argument matchers in regard to method calls that include a variable number of arguments.  Is it even possible?  If so, what should I be doing to make this work?</p>