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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -