Connection implements Runnable { @VisibleForTesting void writeFully(SocketChannel channel, ByteBuffer buffer, boolean forceAsync, DistributionMessage msg) throws IOException, ConnectionException { final DMStats stats = owner.getConduit().getStats(); if (!sharedResource) { stats.incTOSentMsg(); } if (useSyncWrites(forceAsync)) { if (asyncQueuingInProgress) { if (addToQueue(buffer, msg, false)) { return; } } long startLock = stats.startSocketLock(); synchronized (outLock) { stats.endSocketLock(startLock); if (asyncQueuingInProgress) { if (addToQueue(buffer, msg, false)) { return; } } ByteBuffer wrappedBuffer = ioFilter.wrap(buffer); while (wrappedBuffer.remaining() > 0) { int amtWritten = 0; long start = stats.startSocketWrite(true); try { amtWritten = channel.write(wrappedBuffer); } finally { stats.endSocketWrite(true, start, amtWritten, 0); } } } } else { writeAsync(channel, buffer, forceAsync, msg, stats); } } protected  Connection(ConnectionTable connectionTable, Socket socket); private  Connection(ConnectionTable t, boolean preserveOrder, InternalDistributedMember remoteID,
      boolean sharedResource); boolean isSharedResource(); static boolean isDominoThread(); @Override void run(); void setInUse(boolean use, long startTime, long ackWaitThreshold, long ackSAThreshold,
      List connectionGroup); void readAck(final DirectReplyProcessor processor); InternalDistributedMember getRemoteAddress(); @Override String toString(); boolean hasResidualReaderThread(); static final String THREAD_KIND_IDENTIFIER; static final int SMALL_BUFFER_SIZE; @VisibleForTesting
  static final String INITIATING_SUSPECT_PROCESSING; final Object inputBufferLock; static final int MAX_MSG_SIZE; @MutableForTesting
  static volatile boolean FORCE_ASYNC_QUEUE; }
@Test public void canBeMocked() throws Exception { Connection mockConnection = mock(Connection.class); SocketChannel channel = null; ByteBuffer buffer = null; boolean forceAsync = true; DistributionMessage mockDistributionMessage = mock(DistributionMessage.class); mockConnection.writeFully(channel, buffer, forceAsync, mockDistributionMessage); verify(mockConnection, times(1)).writeFully(channel, buffer, forceAsync, mockDistributionMessage); }