Why does this EasyMock test fails?
Hi I have this test below failing an开发者_开发技巧d giving me this error, the fail is on the Verify... but I can't get why.
java.lang.AssertionError: Expectation failure on verify: debug(isA(java.lang.Object)): expected: 1, actual: 0
The test code is this.
public void testLogInfo()
{
JDBCAppender jdbcAppender = createNiceMock(JDBCAppender.class);
Logger logger = createNiceMock(Logger.class);
LogDB logDB = new LogDB(null, null, null, LogDBDriver.ODBC, Level.TRACE);
logDB.setJdbcAppender(jdbcAppender);
logDB.setLogger(logger);
// method call
logger.info(isA(Object.class));
expectLastCall().once();
// replay
replay(logger);
replay(jdbcAppender);
// verify method call
logDB.log(Level.INFO, "10", "Server", "admin", "shortext", "longText","className","methodName");
verify(logger);
}
Just found out what was wrong.
The method call LogDB.log was not calling Logger.info(Object) it was callig Logger.log(Priority, Object).
That's why after the replay, the state was not the same, as it was expecting one kind of call and receiving another.
精彩评论