title: Mockito - InvalidUseOfMatchersException while running using maven, but working directly from eclipse
body: <p>I have mock method for a rest call.</p>
  
  <pre><code>public void createRestClientMock() {
          org.mockito.Mockito.when(
                  restClient.sendResponse(org.mockito.Matchers.anyString(),
                          org.mockito.Matchers.anyString())).thenAnswer(
                  new Answer&lt;Object&gt;() {
                      public Object answer(InvocationOnMock invocation) {
                          Object[] args = invocation.getArguments();
                          actualResponse = args[1].toString();
                          LOG.debug(actualResponse);
                          return null;
                      }
                  });
      }
  </code></pre>
  
  <p>The real method is getting mocked as expected and everything is working fine when i run the junit from eclipse.</p>
  
  <p><strong>But when i try to run the junit from Jenkins using maven build, i am getting the below error:-</strong></p>
  
  <pre><code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
  Misplaced argument matcher detected here:
  
  -&gt; at uk.co.common.Test.createRestClientMock(Test.java:166)
  
  You cannot use argument matchers outside of verification or stubbing.
  Examples of correct usage of argument matchers:
      when(mock.get(anyInt())).thenReturn(null);
      doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
      verify(mock).someMethod(contains("foo"))
  
  Also, this error might show up because you use argument matchers with methods that cannot be mocked.
  Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
  Mocking methods declared on non-public parent classes is not supported.
  </code></pre>
  
  <p>adding the dependencies</p>
  
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
              &lt;version&gt;2.0.13-beta&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hamcrest&lt;/groupId&gt;
              &lt;artifactId&gt;hamcrest-core&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  </code></pre>