DbusLogAccumulator { public DbusLogAccumulator() { this(MAX_NUMBER_OF_LOG_MSGS); } DbusLogAccumulator();  DbusLogAccumulator(int maxNumberMsgs); @Deprecated static void addLog(String s, Logger log); void reset(); void addMessage(String msg); void addMessage(String format, Object val); void addMessage(DebugMessage msg); int getTotalNumberOfMessages(); int getNumberOfMessages(); void prettyLog(Logger log, Level level); static final int MAX_NUMBER_OF_LOG_MSGS; }
@Test public void testDbusLogAccumulator() { DbusLogAccumulator acc = new DbusLogAccumulator(3); Logger log = Logger.getLogger(TestDbusLogAccumulator.class); MyLogger mlog = new MyLogger(TestDbusLogAccumulator.class.getName()); mlog.setLogger(log); acc.addMessage(new DebugMessage("MSG %d", 1)); acc.addMessage(new DebugMessage("MSG %s", "TWO")); acc.addMessage(new DebugMessage("MSG 3")); acc.addMessage(new DebugMessage("MSG %d", 4)); acc.addMessage(new DebugMessage("MSG %s", "FIVE")); acc.addMessage(new DebugMessage("MSG 6")); acc.addMessage("MSG 7"); Assert.assertEquals(7, acc.getTotalNumberOfMessages()); Assert.assertEquals(3, acc.getNumberOfMessages()); acc.prettyLog(mlog, Level.ERROR); Assert.assertFalse(mlog.verifyError("MSG 1")); Assert.assertFalse(mlog.verifyError("MSG TWO")); Assert.assertFalse(mlog.verifyError("MSG 3")); Assert.assertFalse(mlog.verifyError("MSG 4")); Assert.assertTrue(mlog.verifyError("MSG FIVE")); Assert.assertTrue(mlog.verifyError("MSG 6")); Assert.assertTrue(mlog.verifyError("MSG 7")); acc.reset(); mlog.setLevel(Level.DEBUG); acc.addMessage(new DebugMessage("MSG1 %d", 1)); acc.addMessage(new DebugMessage("MSG1 %s", "TWO")); acc.addMessage(new DebugMessage("MSG1 3")); acc.addMessage(new DebugMessage("MSG1 %d", 4)); acc.addMessage(new DebugMessage("MSG1 %s", "FIVE")); acc.addMessage(new DebugMessage("MSG1 6")); acc.addMessage("MSG1 7"); Exception e = new Exception("Exception 1"); acc.addMessage(new DebugMessage("MSG1 %d", 8).setException(e)); Assert.assertEquals(8, acc.getTotalNumberOfMessages()); Assert.assertEquals(3, acc.getNumberOfMessages()); acc.prettyLog(mlog, Level.INFO); Assert.assertFalse(mlog.verifyInfo("MSG1 1")); Assert.assertFalse(mlog.verifyInfo("MSG1 TWO")); Assert.assertFalse(mlog.verifyInfo("MSG1 3")); Assert.assertFalse(mlog.verifyInfo("MSG1 4")); Assert.assertFalse(mlog.verifyInfo("MSG1 FIVE")); Assert.assertTrue(mlog.verifyInfo("MSG1 6")); Assert.assertTrue(mlog.verifyInfo("MSG1 7")); Assert.assertTrue(mlog.verifyInfo("MSG1 8. Exception message = java.lang.Exception: Exception 1. Exception cause = null")); }