### Question:
UnknownAddressMonitor { public void logAttemptToSendToMemberWithNoKnownAddress( MemberId to ) { CappedLogger cappedLogger = loggers.get( to ); if ( cappedLogger == null ) { cappedLogger = new CappedLogger( log ); cappedLogger.setTimeLimit( timeLimitMs, MILLISECONDS, clock ); loggers.put( to, cappedLogger ); } cappedLogger.info(String.format("No address found for %s, probably because the member has been shut down.", to) ); } UnknownAddressMonitor( Log log, Clock clock, long timeLimitMs ); void logAttemptToSendToMemberWithNoKnownAddress( MemberId to );  }### Answer:
@Test public void shouldLogFirstFailure() { Log log = mock( Log.class ); UnknownAddressMonitor logger = new UnknownAddressMonitor( log, testClock(), 100 ); MemberId to = member( 0 ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); verify( log ).info( format( "No address found for %s, probably because the member has been shut down.", to ) ); }
@Test public void shouldThrottleLogging() { Log log = mock( Log.class ); FakeClock clock = testClock(); UnknownAddressMonitor logger = new UnknownAddressMonitor( log, clock, 1000 ); MemberId to = member( 0 ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); clock.forward( 1, MILLISECONDS ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); verify( log, times( 1 ) ) .info( format( "No address found for %s, probably because the member has been shut " + "down.", to ) ); }
@Test public void shouldResumeLoggingAfterQuietPeriod() { Log log = mock( Log.class ); FakeClock clock = testClock(); UnknownAddressMonitor logger = new UnknownAddressMonitor( log, clock, 1000 ); MemberId to = member( 0 ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); clock.forward( 20001, MILLISECONDS ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); clock.forward( 80001, MILLISECONDS ); logger.logAttemptToSendToMemberWithNoKnownAddress( to ); verify( log, times( 3 ) ) .info( format( "No address found for %s, probably because the member has been shut " + "down.", to ) ); }