java - jUnit Unexpected method call DAO Easymock check User -


i have problem testing check user method dao. here code:

private userservice service; private userdao mockdao;  @before public void setup(){     service=new userservice();     mockdao=createmock(userdao.class);     service.setuserdao(mockdao); }  @test public void testcheckuserlogin(){      user results=new user();     user test=new user();     test.setusername("x");     test.setpass("y");      easymock.expect(mockdao.checkuser(test)).andreturn(results.getiduser());            easymock.replay(mockdao);    assertequals(service.login(test),service.login(results));    easymock.verify(mockdao); } 

when run error:

  java.lang.assertionerror:    unexpected method call userdao.checkuser(com.sot.car.model.user@4e527622): 

i don't know why error? have added easymock.expect method check user

because, when use objects in mocking, need use matchers perform object comparision.

in case, can either set matcher match or if happy user object use easymock.isa(user.class) e.g. easymock.expect(mockdao.checkuser(easymock.isa(user.class))).andreturn(results.getiduser());

or

easymock.expect(mockdao.checkuser(test)).andreturn(results.getiduser());
easymock.reportmatcher(new matcherclass()); // refer : http://www.easymock.org/easymock2_2_documentation.html


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -