title: Powermockito : java.lang.IllegalArgumentException: argument type mismatch
body: <p>I don't have much experience with Mocking, I have recently started using it in my Junit test cases. However, I am having difficulties understanding the execution.</p>
  
  <p>I am getting IllegalArgumentException when I try this code</p>
  
  <pre><code>PowerMockito.doNothing().when(spyObject, "lockUser", String.class, User.class);
  </code></pre>
  
  <p>But when I provide the values that the lockUser would recieve at the time of execution, everything works as expected. </p>
  
  <p>Working code</p>
  
  <pre><code>PowerMockito.doNothing().when(spyObject, "lockUser", "my_text", userMock);
  </code></pre>
  
  <p>I am rather confused with this behavior. I was expecting identical behaviour. 
  Could someone explain why this is happening ?</p>
  
  <p>In addition when I have the following code</p>
  
  <pre><code>PowerMockito.doNothing().when(spyObject, "lockUser", anyString(), anyObject());
  </code></pre>
  
  <p>The method is no longer mocked and the real method is invoked. </p>
  
  <p>Interestingly I have another method with same name "lockUser" which takes different number of parameters. And in my other test method, I have used only Matchers (anyObject(), anyString() etc) and that works as expected.</p>
  
  <pre><code>PowerMockito.doNothing().when(spyObject, "lockUser", anyObject(), anyString(), anyString(), anyString());
  </code></pre>
  
  <p>All lockUser methods are priavate.</p>
  
  <p>I am working with Mockito 1.9.5 together with PowerMock 1.5.6</p>
  
  <p>Any help is greatly appreciated</p>
  
  <p>Edit 
  Additional Code to make it clear</p>
  
  <pre><code>Class Core {
  public Worker getWorker(String workerId) {
    // Get worker from Map&lt;String, Worker&gt; fID_WRK with workerId as key 
    // Get user from worker (I have mocked this part, so my mock user is     
    //   returned)
    If(user.isTooOld()) {
     lockUserAndNotify(reason, user);
     throw new UserLockedException("Too old");
     }
  
  private void lockUserAndNotify(String reason, User user) {
    lockUserAndNotify(reason, user.fname, user.lname); // locks user and notifies
  }
  
  public getUser(String login, String password) {
    // find user in database
    if(user password is too old) {
      lockUserAndNotify(dbConnection, fname, lname, userId);
    }
  }
  
  private lockUserAndNotify(Connection dbConn, String fName, String lName, String
                   userId) {
    //method call to lock the user
    //method call to notify the admin
  }
  
  
  }
  </code></pre>
  
  <p>My Test class</p>
  
  <pre><code>Class CoreTest {
    @Test (expected = UserLockedException.class)
    public void getUser_ThrowsException() throws                  
               Exception{
  
      Core core = new Core();
      Core coreSpy = PowerMockito.spy(core);
  
      when(userMock.isPwdUpdateTimeExpired()).thenReturn(true);
      PowerMockito.doNothing().when(coreSpy, "lockUserAndNotify", 
       anyObject(), anyString(), anyString(), anyString(), anyString());
  
      admin4.UserManager.getUser("l.user1","password");
  
    }
  
  @Test (expected = UserLockedException.class)
        public void getWorker_ThrowsException() throws                  
                   Exception{
  
          Core core = new Core();
          Core coreSpy = PowerMockito.spy(core);
  
          Map workerMap = Whitebox.getInternalState(coreSpy, "fID_WRK");
          Map workerMapSpy = PowerMockito.spy(workerMap);
  
          when(workerMapSpy.getWorker("12345")).thenReturn(workerMock);
          when(workerMock.getUser()).thenReturn(userMock);
          when(userMock.isTooOld()).thenReturn(true);
          PowerMockito.doNothing().when(coreSpy, "lockUserAndNotify", 
           anyString(), anyObject());
  
          admin4.UserManager.getWorker("123445");
  
        }
  }
  </code></pre>
  
  <p>So the test getUser_ThrowsException works as expected, but getWorker_ThrowsException does not. </p>