title: Mocking a DateFormat class in junit test
body: <p>I am trying to Mock a DateFormat class, since it has no purpose in the scope of my unit test. I am using the org.mockito.Mockito library.</p>
  
  <p>Following code:</p>
  
  <pre><code>import static org.mockito.Mockito.when;
  import static org.mockito.Mockito.any;
  import org.mockito.Mock;
  import org.mockito.MockitoAnnotations;
  
  import org.junit.Before;
  
  public class someTest {
  
      @Mock
      DateFormat formatter; 
  
      @Before
      public void before() {
          MockitoAnnotations.initMocks(this);
          when(formatter.format(any(Date.class))).thenReturn("2017-02-06");
      }
  }
  </code></pre>
  
  <p>Gives following error:</p>
  
  <blockquote>
    <p>org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
    Invalid use of argument matchers! 3 matchers expected, 1 recorded:</p>
    
    <p>-> at someTest.before(someTest.java:33)</p>
    
    <p>This exception may occur if matchers are combined with raw values:
        //incorrect:
        someMethod(anyObject(), "raw String"); When using matchers, all arguments have to be provided by matchers. For example:
        //correct:
        someMethod(anyObject(), eq("String by matcher"));</p>
    
    <p>For more info see javadoc for Matchers class.</p>
    
    <p>at java.text.DateFormat.format(Unknown Source)<br>
    at
    someTest.before(someTest.java:33)</p>
  </blockquote>
  
  <p>How do I mock the DateFormat class in a correct way?</p>