title: Mockito 'Misplaced argument detected here' in Java
body: <p>So I have this Mockito unit test:</p>
  
  <pre><code>@Test
      public void createCard() {
  
      when(jwtServiceMock.getId(anyString())).thenReturn(validUserToken);
      when(profileServiceMock.getProfile(validUserToken)).thenReturn(mock(Profile.class));
      when(cardServiceMock.countViewableCardsCreatedOrOwnedBy(anyObject())).thenReturn(5L);
      when(cardServiceMock.countCardsCreatedOrOwned(anyObject())).thenReturn(10L);
  
      final Card expectedCard = getCard();
  
      when(cardServiceMock.createCard(anyString(), anyListOf(String.class), anyListOf(String.class),
              any(CreatorRecipientCriteria.class), anyListOf(ImageMask.class))).thenReturn(expectedCard);
  
      when(imageService.createCardImage(any(MultipartFile.class), anyString(), any(ImageMask.class))).thenReturn(any(Orientation.class));
  
      final Card receivedCard = cardControllerMock.createCard(validUserToken, mock(MultipartFile.class), "card");
  
      assertEquals(receivedCard, expectedCard);
  }
  </code></pre>
  
  <p>It looks fine for me, but for some reason it says:</p>
  
  <pre><code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
  Misplaced argument matcher detected here:
  
  -&gt; at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53)
  
  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"))
  </code></pre>
  
  <p>I have been trying to find out what's wrong for a long time, but still not sure what's causing the issue. Any hint please?</p>
  
  <p>Thanks.</p>