java - How to mock a Dao twice but being called with same Object? -


how mock dao being called in test method twice same object different internal state (of parameter).

user user = new user(); user.setactivity(false); int prevactivity = accessdao.calculatework(user); user.setactivity(true); int predactivity = accessdao.calculatework(user);   if(prevactivity==0) {     //someaction }  ...  if(predactivity<15) {     //someotheraction. } 

i cannot change code. there way in mockito following situation?

you can use mockito's answers that.

atomicinteger counter = new atomicinteger(); when(accessdao.calculatework(user)).thenanswer(new answer() {   object answer(invocationonmock invocation) {     if (counter.getandincrement() == 0) return somevalue;     return anothervalue;   } }); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -