开发者

Why does this EasyMock test fails?

开发者 https://www.devze.com 2023-02-19 14:56 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消