LogMarkerImpl extends ComponentSupport implements LogMarker { @Override public void markLog(final String message) { LoggerLevel loggerLevel = logManager.getLoggerEffectiveLevel(log.getName()); if (LoggerLevel.INFO.compareTo(loggerLevel) < 0) { logManager.setLoggerLevel(log.getName(), LoggerLevel.INFO); } String asterixes = Strings.repeat("*", message.length() + 4); log.info("\n{}\n* {} *\n{}", asterixes, message, asterixes); eventManager.post(new LogMarkInsertedEvent(message)); } @Inject  LogMarkerImpl(final LogManager logManager, final EventManager eventManager); @Override void markLog(final String message);  }
@Test public void testMarkLog_EmitEvent() { logMarker.markLog("test"); ArgumentCaptor<LogMarkInsertedEvent> argCaptor = ArgumentCaptor.forClass(LogMarkInsertedEvent.class); verify(eventManager).post(argCaptor.capture()); assertThat(argCaptor.getValue().getMessage(), is("test")); }
@Test public void testMarkLog_EnsureLogLevel() { for (LoggerLevel level : EnumSet.complementOf(EnumSet.of(LoggerLevel.DEFAULT))) { reset(logManager); when(logManager.getLoggerEffectiveLevel(LOG_NAME)).thenReturn(level); logMarker.markLog("test"); try { if (EnumSet.of(LoggerLevel.OFF, LoggerLevel.ERROR, LoggerLevel.WARN).contains(level)) { verify(logManager).setLoggerLevel(LOG_NAME, LoggerLevel.INFO); } else { verify(logManager, never()).setLoggerLevel(anyObject(), anyObject()); } } catch (AssertionError e) { throw new AssertionError("Mishandled log level " + level, e); } } }