In my unit test for DAO method, I am trying to test the update user method. But, I have to create an user and then update it. So my mock DAO is expecting the addUser call, but then when I am, calling the update method it is complaining
java.lang.AssertionError: Unexpected method call UserAdminDAO.updateUser(null):
here is the code snipper
expect(userAdminDAO.addNewUser(u1)).andReturn(u1);
replay(userAdminDAO);
User u2 = (User)userService.addNewUser(ar);
Assert.assertEquals(u.getUserName(), u2.getUserName());
u2.setUserName("new modified");
userAdminDAO.updateUser(u2); //error is on this line
expectLastCall().once().andAnswer(new IAnswer<User>() {
public User answer() {
return null;
}
});
replay(userAdminDAO);
userService.updateUser(u2);