### Question:
LogTemplate { public final boolean log(C context, LogMessageSource<C> messageSource) { final boolean enabled = isEnabled(context); if (enabled) { log(messageSource.getLogMessage(context)); } return enabled; }  final boolean log(C context, LogMessageSource<C> messageSource);  }### Answer:
@Test public void testJUL() { JULLogTemplate logTemplate = toJUL(getClass().getName(), Level.INFO); logMessage = "Test JUL"; logTemplate.log(null, this); }
@Test public void testSLF4J() { SLF4JLogTemplate logTemplate = toSLF4J(getClass().getName(), "info", null); logMessage = "Test SLF4J without marker"; logTemplate.log(null, this); logTemplate = toSLF4J(getClass().getName(), "info", "marker"); logMessage = "Test SLF4J with marker"; logTemplate.log(null, this); }
@Test public void testCounter() { TestLogTemplate logTemplate1 = new TestLogTemplate(); logMessage = "Test Counter"; LogTemplate<Object> logTemplate2 = everyNSplits(logTemplate1, 3); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); assertTrue(logTemplate2.log(null, this)); assertEquals(logTemplate1.getMessage(), logMessage); logTemplate1.clear(); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); assertTrue(logTemplate2.log(null, this)); assertEquals(logTemplate1.getMessage(), logMessage); logTemplate1.clear(); }
@Test public void testPeriodic() throws InterruptedException { TestLogTemplate logTemplate1 = new TestLogTemplate(); logMessage = "Test Periodic"; SimonClock clock = mock(SimonClock.class); long startTime = 1000; when(clock.milliTime()).thenReturn(startTime); LogTemplate logTemplate2 = everyNMilliseconds(logTemplate1, 500L, clock); when(clock.milliTime()).thenReturn(startTime + 300L); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); when(clock.milliTime()).thenReturn(startTime + 550L); assertTrue(logTemplate2.log(null, this)); assertEquals(logTemplate1.getMessage(), logMessage); logTemplate1.clear(); assertFalse(logTemplate2.log(null, this)); assertNull(logTemplate1.getMessage()); when(clock.milliTime()).thenReturn(startTime + 1550L); assertTrue(logTemplate2.log(null, this)); assertEquals(logTemplate1.getMessage(), logMessage); logTemplate1.clear(); }