title: JMockit: "Misplaced argument matcher detected here" when mocking an interface
body: <p>Following is the test code:</p>
  
  <pre><code>package a.b.c.concurrent.locks;
  
  import static org.mockito.Matchers.any;
  import static org.mockito.Matchers.anyLong;
  import static org.mockito.Mockito.when;
  
  import java.util.concurrent.TimeUnit;
  import java.util.concurrent.locks.Lock;
  
  import mockit.Mocked;
  
  import org.apache.log4j.ConsoleAppender;
  import org.apache.log4j.Logger;
  import org.apache.log4j.PatternLayout;
  import org.junit.BeforeClass;
  import org.junit.Test;
  
  public class TestLockConcludesProperly {
  
      private static LockProxy lockProxy;
  
      @BeforeClass
      public static void setUpBeforeClass() throws Exception {
          Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout()));
      }
  
      @Test
      public void testAquireLockInFirstIteration(@Mocked Lock mockLock) throws Exception {
  
          when(mockLock.tryLock(anyLong(), any(TimeUnit.class))).thenReturn(true);
  
          lockProxy = new LockProxy(mockLock, 2, TimeUnit.MILLISECONDS);
  
          lockProxy.lock();
  
      }
  }
  </code></pre>
  
  <p>The error I get and just can't figure out, though it is probably some misconfiguration on my part, is:</p>
  
  <pre><code>Tests in error: 
    testAquireLockInFirstIteration(a.b.c.concurrent.locks.TestLockConcludesProperly): 
  Misplaced argument matcher detected here:
  
  -&gt; at a.b.c.concurrent.locks.TestLockConcludesProperly.testAquireLockInFirstIteration(TestLockConcludesProperly.java:34)
  -&gt; at a.b.c.concurrent.locks.TestLockConcludesProperly.testAquireLockInFirstIteration(TestLockConcludesProperly.java:34)
  
  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().
  </code></pre>
  
  <p>What am I doing wrong?</p>