title: Mockito mock method with comparing parameters - Misplaced argument matcher detected here
body: <p>I'm trying to mock a method of EntityPersistor</p>
  
  <pre><code>T getSingleResultFromTypedQuery(String queryString, Map&lt;String, Object&gt; params);
  </code></pre>
  
  <p>I want to check if queryString matches a specific queryString and if params contains a specific value. If those two conditions are true, I want to return an specific object xy.</p>
  
  <p>I'm new to mocking and mockito, but I tried to achieve this with two ArgumentMatcher inside the when() call.</p>
  
  <pre><code>EntityPersistor&lt;UserEntity&gt; entityPersistorMocked = mock(EntityPersistorStub.class);
  
  when(entityPersistorMocked.getSingleResultFromTypedQuery(argThat(new ArgumentMatcher&lt;String&gt;() {
          @Override
          public boolean matches(Object o) {
              return "SELECT u FROM UserEntity u where u.username = :u".equals(o.toString());
          }
      }), argThat(new ArgumentMatcher&lt;Map&lt;String, Object&gt;&gt;() {
          @Override
          public boolean matches(Object o) {
              HashMap&lt;String, Object&gt; params = (HashMap&lt;String, Object&gt;) o;
              if (params.containsKey('u') &amp;&amp; params.get('u').toString().equals("hans")) {
                  return true;
              } else {
                  return false;
              }
          }
      })))
              .thenAnswer(new Answer&lt;UserEntity&gt;() {
                  @Override
                  public UserEntity answer(InvocationOnMock invocation) throws Throwable {
                      UserEntity user = new UserEntity();
                      user.setUserId(1);
                      user.setDisplayName("Dummy User");
                      user.setUsername("hans");
                      user.setPassword("pass");
                      return user;
                  }
              });
  </code></pre>
  
  <p>compiles successfull but won't run:</p>
  
  <blockquote>
  <pre><code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
  </code></pre>
    
    <p>Misplaced argument matcher detected here:</p>
  </blockquote>
  
  <p>how can I fix that? or is there a better way to mock a method and define a specific return case (if param 1 eq x and param 2 eq y)?</p>