HotKeyLogger { public void logHotKeyDetection(String userStepName, Duration hotKeyAge) { if (isThrottled()) { return; } LOG.warn(getHotKeyMessage(userStepName, TimeUtil.toCloudDuration(hotKeyAge))); } HotKeyLogger();   HotKeyLogger(Clock clock); void logHotKeyDetection(String userStepName, Duration hotKeyAge);  }
@Test @SuppressWarnings("Slf4jIllegalPassedClass") public void logsHotKeyMessage() { mockStatic(LoggerFactory.class); Logger logger = mock(Logger.class); when(LoggerFactory.getLogger(any(Class.class))).thenReturn(logger); HotKeyLogger hotKeyLogger = new HotKeyLogger(clock); hotKeyLogger.logHotKeyDetection("TEST_STEP_ID", Duration.standardHours(1)); hotKeyLogger.logHotKeyDetection("TEST_STEP_ID", Duration.standardHours(1)); verify(logger, Mockito.times(1)).warn(anyString()); }
@Test public void logsHotKeyMessage() { mockStatic(LoggerFactory.class); Logger logger = mock(Logger.class); when(LoggerFactory.getLogger(any(Class.class))).thenReturn(logger); HotKeyLogger hotKeyLogger = new HotKeyLogger(clock); hotKeyLogger.logHotKeyDetection("TEST_STEP_ID", Duration.standardHours(1)); hotKeyLogger.logHotKeyDetection("TEST_STEP_ID", Duration.standardHours(1)); verify(logger, Mockito.times(1)).warn(anyString()); }