You can use the mockit.Invocation
class to invoke the original method that has been mocked by Deencapsulation.invoke()
. The following code snippet delegates to original method on second method invocation.
new NonStrictExpectations(mCurrencyDao) {
{
invoke(mCurrencyDao, "readSqlQuery", withAny(String.class));
result = new Delegate<String>() {
@SuppressWarnings("unused")
String delegate(Invocation invocation) {
if (invocation.getInvocationIndex() == 0) {
return prepareTestSQL(pAllKeysForTest);
} else {
return invocation.proceed();
}
}
};
times = 2;
}
};
mCurrencyDao.loadAll(lToday);
mCurrencyDao.loadAll(lTomorrow);