### Question:
AbstractPeerConnection implements PeerConnection { @Override public void disconnect(final DisconnectReason reason) { if (disconnected.compareAndSet(false, true)) { LOG.debug("Disconnecting ({}) from {}", reason, peerInfo); connectionEventDispatcher.dispatchDisconnect(this, reason, false); doSend(null, DisconnectMessage.create(reason)); closeConnection(); } } protected  AbstractPeerConnection(
      final Peer peer,
      final PeerInfo peerInfo,
      final InetSocketAddress localAddress,
      final InetSocketAddress remoteAddress,
      final String connectionId,
      final CapabilityMultiplexer multiplexer,
      final PeerConnectionEventDispatcher connectionEventDispatcher,
      final LabelledMetric<Counter> outboundMessagesCounter); @Override void send(final Capability capability, final MessageData message); @Override PeerInfo getPeerInfo(); @Override Capability capability(final String protocol); @Override Peer getPeer(); @Override Set<Capability> getAgreedCapabilities(); @Override void terminateConnection(final DisconnectReason reason, final boolean peerInitiated); @Override void disconnect(final DisconnectReason reason); @Override boolean isDisconnected(); @Override InetSocketAddress getLocalAddress(); @Override InetSocketAddress getRemoteAddress(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void disconnect() { final AtomicBoolean disconnectCallbackInvoked = new AtomicBoolean(false); final DisconnectReason disconnectReason = DisconnectReason.USELESS_PEER; connectionEvents.subscribeDisconnect( (conn, reason, fromPeer) -> { disconnectCallbackInvoked.set(true); assertThat(reason).isEqualTo(disconnectReason); assertThat(conn).isEqualTo(connection); assertThat(fromPeer).isFalse(); assertThat(conn.isDisconnected()).isTrue(); assertThatThrownBy(() -> connection.send(null, PingMessage.get())); }); connection.disconnect(disconnectReason); assertThat(disconnectCallbackInvoked).isTrue(); assertThat(connection.isDisconnected()).isTrue(); assertThat(connection.closedCount).isEqualTo(1); assertThat(connection.sentMessages.size()).isEqualTo(1); assertThat(connection.sentMessages.get(0).messageData.getCode()) .isEqualTo(WireMessageCodes.DISCONNECT); }