### Question:
PeerReputationManager implements DisconnectCallback { @Override public void onDisconnect( final PeerConnection connection, final DisconnectReason reason, final boolean initiatedByPeer) { if (shouldBlock(reason, initiatedByPeer)) { blacklist.add(connection.getPeer()); } } PeerReputationManager(final PeerPermissionsDenylist blacklist); @Override void onDisconnect(
      final PeerConnection connection,
      final DisconnectReason reason,
      final boolean initiatedByPeer);  }### Answer:
@Test public void doesNotBlacklistPeerForNormalDisconnect() { final PeerConnection peer = generatePeerConnection(); checkPermissions(blacklist, peer.getPeer(), true); peerReputationManager.onDisconnect(peer, DisconnectReason.TOO_MANY_PEERS, false); checkPermissions(blacklist, peer.getPeer(), true); }
@Test public void blacklistPeerForBadBehavior() { final PeerConnection peer = generatePeerConnection(); checkPermissions(blacklist, peer.getPeer(), true); peerReputationManager.onDisconnect(peer, DisconnectReason.BREACH_OF_PROTOCOL, false); checkPermissions(blacklist, peer.getPeer(), false); }
@Test public void doesNotBlacklistPeerForOurBadBehavior() { final PeerConnection peer = generatePeerConnection(); checkPermissions(blacklist, peer.getPeer(), true); peerReputationManager.onDisconnect(peer, DisconnectReason.BREACH_OF_PROTOCOL, true); checkPermissions(blacklist, peer.getPeer(), true); }
@Test public void blacklistIncompatiblePeer() { final PeerConnection peer = generatePeerConnection(); checkPermissions(blacklist, peer.getPeer(), true); peerReputationManager.onDisconnect( peer, DisconnectReason.INCOMPATIBLE_P2P_PROTOCOL_VERSION, false); checkPermissions(blacklist, peer.getPeer(), false); }
@Test public void blacklistIncompatiblePeerWhoIssuesDisconnect() { final PeerConnection peer = generatePeerConnection(); checkPermissions(blacklist, peer.getPeer(), true); peerReputationManager.onDisconnect( peer, DisconnectReason.INCOMPATIBLE_P2P_PROTOCOL_VERSION, true); checkPermissions(blacklist, peer.getPeer(), false); }