HotKeyLogger { protected boolean isThrottled() { long nowMs = clock.currentTimeMillis(); if (nowMs - prevHotKeyDetectionLogMs < loggingPeriod.getMillis()) { return true; } prevHotKeyDetectionLogMs = nowMs; return false; } HotKeyLogger();   HotKeyLogger(Clock clock); void logHotKeyDetection(String userStepName, Duration hotKeyAge);  }
@Test public void throttlesLoggingHotKeyMessage() { HotKeyLogger hotKeyLogger = new HotKeyLogger(clock); clock.setTime(Clock.SYSTEM.currentTimeMillis()); assertFalse(hotKeyLogger.isThrottled()); assertTrue(hotKeyLogger.isThrottled()); clock.setTime(clock.currentTimeMillis() + Duration.standardMinutes(5L).getMillis()); assertFalse(hotKeyLogger.isThrottled()); assertTrue(hotKeyLogger.isThrottled()); clock.setTime(clock.currentTimeMillis() + Duration.standardMinutes(5L).getMillis()); assertFalse(hotKeyLogger.isThrottled()); assertTrue(hotKeyLogger.isThrottled()); }