title: InvocationTargetException in Easy mock of JUnit
body: <p>I am facing an issue while running <code>JUnit</code> using <code>EasyMock</code>. Please find below the source files - <code>UserTest.java</code> (JUnit file) and <code>UserFinder.java</code> (Application file to be unit tested).</p>
  
  <p><strong>UserTest.java</strong></p>
  
  <pre><code>Class UserTest
  {
    ...
    @Test
    public void testFindUserFunction() throws Exception {
  
  
      DAO daoMock = EasyMock.createMock(DAO.class);       
      User user = new User("john", "stephen", "city street", "bangalore");
      EasyMock.expect(daoMock.userExists(user).andReturn(true);
      EasyMock.replay(daoMock);       
      String userFirstName = user.getFirstName();
      User resultUser = UserFinder.findUser(userFirstName, daoMock);      
      PowerMock.verify(daoMock);      
      Assert.assertEquals(user, resultUser);
    }
  }
  </code></pre>
  
  <p><strong>UserFinder.java</strong></p>
  
  <pre><code>Class UserFinder {
  ...
  ...
  public User findUser(String userFirstName, DAO dao)
  {
  return dao.findUser(userFirstName);
  }
  ...
  ...
  }
  </code></pre>
  
  <p>In JUnit, I have created a mock object <code>daoMock</code> and added below <code>expect</code> behavior.</p>
  
  <pre><code>EasyMock.expect(daoMock.userExists(user).andReturn(true);
  </code></pre>
  
  <p>In the below line of <strong>UserFinder.java</strong>, I need to pass <code>daoMock</code> as the class is already existing and designed in that way. When the below line is executed through JUnit, I am getting <code>java.lang.reflect.InvocationTargetException</code>.</p>
  
  <pre><code>User resultUser = UserFinder.findUser(userFirstName, daoMock);
  </code></pre>
  
  <p>I am new to <code>EasyMock</code> and I thought setting <code>expect</code> adds to the behavior of the <code>daoMock</code> object but it is not. Please help me about how to call <code>dao.findUser</code> line as I cannot mock this line since it is in application file. How can I mock and run the JUnit for this case in <code>EasyMock</code>. Thanks.</p>