Logging { public static long log(final Logger logger, final String message) { if (logger.isLoggable(Level.FINEST)) { logger.log(Level.FINEST, message); } return System.currentTimeMillis(); } private  Logging(); static long log(final Logger logger,
                           final String message); static long log(final Logger logger,
                           final String message,
                           final long previousTimeMillis);  }
@Test public void testLogEnabled() { when(logger.isLoggable(Level.FINEST)).thenReturn(true); assertThat(Logging.log(logger, MESSAGE)).isGreaterThan(0); verify(logger).log(eq(Level.FINEST), eq(MESSAGE)); }
@Test public void testLogWithPreviousTimeTimeMillisEnabled() { when(logger.isLoggable(Level.FINEST)).thenReturn(true); assertThat(Logging.log(logger, MESSAGE, PREVIOUS_TIME_MILLIS)).isGreaterThanOrEqualTo(PREVIOUS_TIME_MILLIS); verify(logger).log(eq(Level.FINEST), contains(MESSAGE)); }
@Test public void testLogDisabled() { when(logger.isLoggable(Level.FINEST)).thenReturn(false); assertThat(Logging.log(logger, MESSAGE)).isGreaterThan(0); verify(logger, never()).log(any(Level.class), anyString()); }
@Test public void testLogWithPreviousTimeTimeMillisDisabled() { when(logger.isLoggable(Level.FINEST)).thenReturn(false); assertThat(Logging.log(logger, MESSAGE, PREVIOUS_TIME_MILLIS)).isGreaterThanOrEqualTo(PREVIOUS_TIME_MILLIS); verify(logger, never()).log(any(Level.class), anyString()); }