### Question:
PeerReputation { public Optional<DisconnectReason> recordUselessResponse(final long timestamp) { uselessResponseTimes.add(timestamp); while (shouldRemove(uselessResponseTimes.peek(), timestamp)) { uselessResponseTimes.poll(); } if (uselessResponseTimes.size() >= USELESS_RESPONSE_THRESHOLD) { LOG.debug("Disconnection triggered by exceeding useless response threshold"); return Optional.of(DisconnectReason.USELESS_PEER); } else { return Optional.empty(); } }  Optional<DisconnectReason> recordRequestTimeout(final int requestCode); void resetTimeoutCount(final int requestCode); Map<Integer, AtomicInteger> timeoutCounts(); Optional<DisconnectReason> recordUselessResponse(final long timestamp);  }### Answer:
@Test public void shouldOnlyDisconnectWhenEmptyResponseThresholdReached() { assertThat(reputation.recordUselessResponse(1001)).isEmpty(); assertThat(reputation.recordUselessResponse(1002)).isEmpty(); assertThat(reputation.recordUselessResponse(1003)).isEmpty(); assertThat(reputation.recordUselessResponse(1004)).isEmpty(); assertThat(reputation.recordUselessResponse(1005)).contains(USELESS_PEER); }
@Test public void shouldDiscardEmptyResponseRecordsAfterTimeWindowElapses() { assertThat(reputation.recordUselessResponse(1001)).isEmpty(); assertThat(reputation.recordUselessResponse(1002)).isEmpty(); assertThat(reputation.recordUselessResponse(1003)).isEmpty(); assertThat(reputation.recordUselessResponse(1004)).isEmpty(); assertThat( reputation.recordUselessResponse( 1001 + PeerReputation.USELESS_RESPONSE_WINDOW_IN_MILLIS + 1)) .isEmpty(); }