@Test public void interleavedMessagesShouldBeLoggedOnlyOnce() { OnlyOnceLogger onlyOnceLogger = new OnlyOnceLogger(logger); onlyOnceLogger .infoOnce("my message", "argument 1", "argument 2", "argument 3"); onlyOnceLogger .infoOnce("my other message", "argument 1", "argument 2", "argument 3"); onlyOnceLogger .infoOnce("my message", "argument 1", "argument 2", "argument 3"); onlyOnceLogger .infoOnce("my other message", "argument 1", "argument 2", "argument 3"); verify(logger, times(1)).info("my message", "argument 1", "argument 2", "argument 3"); verify(logger, times(1)).info("my other message", "argument 1", "argument 2", "argument 3"); }
public void infoOnce(String format, Object... arguments) { if (maxHistorySizeReached()) return; if (!logger.isInfoEnabled()) return; LogEntry logEntry = new LogEntry(format, arguments); if (shouldLog(logEntry)) logger.info(format, arguments); }
OnlyOnceLogger { public void infoOnce(String format, Object... arguments) { if (maxHistorySizeReached()) return; if (!logger.isInfoEnabled()) return; LogEntry logEntry = new LogEntry(format, arguments); if (shouldLog(logEntry)) logger.info(format, arguments); } }
OnlyOnceLogger { public void infoOnce(String format, Object... arguments) { if (maxHistorySizeReached()) return; if (!logger.isInfoEnabled()) return; LogEntry logEntry = new LogEntry(format, arguments); if (shouldLog(logEntry)) logger.info(format, arguments); } OnlyOnceLogger(Logger logger);  OnlyOnceLogger(Logger logger, int maxHistorySize); }
OnlyOnceLogger { public void infoOnce(String format, Object... arguments) { if (maxHistorySizeReached()) return; if (!logger.isInfoEnabled()) return; LogEntry logEntry = new LogEntry(format, arguments); if (shouldLog(logEntry)) logger.info(format, arguments); } OnlyOnceLogger(Logger logger);  OnlyOnceLogger(Logger logger, int maxHistorySize); void infoOnce(String format, Object... arguments); }
OnlyOnceLogger { public void infoOnce(String format, Object... arguments) { if (maxHistorySizeReached()) return; if (!logger.isInfoEnabled()) return; LogEntry logEntry = new LogEntry(format, arguments); if (shouldLog(logEntry)) logger.info(format, arguments); } OnlyOnceLogger(Logger logger);  OnlyOnceLogger(Logger logger, int maxHistorySize); void infoOnce(String format, Object... arguments); static final int DEFAULT_HISTORY_SIZE; }