@Test public void testOnBytesWritten() throws Exception { Field mSocketIoThreadsField = mBluetoothServerThread.getClass() .getDeclaredField("mSocketIoThreads"); mSocketIoThreadsField.setAccessible(true); CopyOnWriteArrayList<BluetoothSocketIoThread> mySocketIoThreads = new CopyOnWriteArrayList<>(); mSocketIoThreadsField.set(mBluetoothServerThread, mySocketIoThreads); mySocketIoThreads.add(mMockBluetoothSocketIoThread); mBluetoothServerThread.onBytesWritten("aText".getBytes(), 15, mMockBluetoothSocketIoThread); verify(mMockBluetoothSocketIoThread, never()).close(anyBoolean(), anyBoolean()); assertThat("The thread is removed from the list of IO threads", mySocketIoThreads.isEmpty(), is(true)); }
@Override public void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who) { final long threadId = who.getId(); Log.d(TAG, "onBytesWritten: " + size + " bytes successfully written (thread ID: " + threadId + ")"); if (who.getPeerProperties() != null) { Log.d(TAG, "onBytesWritten: Peer props = " + who.getPeerProperties().toString()); } boolean threadRemoved = removeThreadFromList(who, false); if (threadRemoved) { Log.d(TAG, "Handshake thread disposed (thread ID: " + threadId + ")"); } else { Log.e(TAG, "Failed to find the thread from the list (thread ID: " + threadId + ")"); } Log.d(TAG, "onIncomingConnectionConnected socket:" + who.getSocket() + ", properties: " + who.getPeerProperties()); mListener.onIncomingConnectionConnected(who.getSocket(), who.getPeerProperties()); }
BluetoothServerThread extends AbstractBluetoothThread implements BluetoothSocketIoThread.Listener { @Override public void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who) { final long threadId = who.getId(); Log.d(TAG, "onBytesWritten: " + size + " bytes successfully written (thread ID: " + threadId + ")"); if (who.getPeerProperties() != null) { Log.d(TAG, "onBytesWritten: Peer props = " + who.getPeerProperties().toString()); } boolean threadRemoved = removeThreadFromList(who, false); if (threadRemoved) { Log.d(TAG, "Handshake thread disposed (thread ID: " + threadId + ")"); } else { Log.e(TAG, "Failed to find the thread from the list (thread ID: " + threadId + ")"); } Log.d(TAG, "onIncomingConnectionConnected socket:" + who.getSocket() + ", properties: " + who.getPeerProperties()); mListener.onIncomingConnectionConnected(who.getSocket(), who.getPeerProperties()); } }
BluetoothServerThread extends AbstractBluetoothThread implements BluetoothSocketIoThread.Listener { @Override public void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who) { final long threadId = who.getId(); Log.d(TAG, "onBytesWritten: " + size + " bytes successfully written (thread ID: " + threadId + ")"); if (who.getPeerProperties() != null) { Log.d(TAG, "onBytesWritten: Peer props = " + who.getPeerProperties().toString()); } boolean threadRemoved = removeThreadFromList(who, false); if (threadRemoved) { Log.d(TAG, "Handshake thread disposed (thread ID: " + threadId + ")"); } else { Log.e(TAG, "Failed to find the thread from the list (thread ID: " + threadId + ")"); } Log.d(TAG, "onIncomingConnectionConnected socket:" + who.getSocket() + ", properties: " + who.getPeerProperties()); mListener.onIncomingConnectionConnected(who.getSocket(), who.getPeerProperties()); } BluetoothServerThread(
            Listener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString); }
BluetoothServerThread extends AbstractBluetoothThread implements BluetoothSocketIoThread.Listener { @Override public void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who) { final long threadId = who.getId(); Log.d(TAG, "onBytesWritten: " + size + " bytes successfully written (thread ID: " + threadId + ")"); if (who.getPeerProperties() != null) { Log.d(TAG, "onBytesWritten: Peer props = " + who.getPeerProperties().toString()); } boolean threadRemoved = removeThreadFromList(who, false); if (threadRemoved) { Log.d(TAG, "Handshake thread disposed (thread ID: " + threadId + ")"); } else { Log.e(TAG, "Failed to find the thread from the list (thread ID: " + threadId + ")"); } Log.d(TAG, "onIncomingConnectionConnected socket:" + who.getSocket() + ", properties: " + who.getPeerProperties()); mListener.onIncomingConnectionConnected(who.getSocket(), who.getPeerProperties()); } BluetoothServerThread(
            Listener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString); @Override void run(); @Override synchronized void shutdown(); @Override void onBytesRead(byte[] bytes, int size, BluetoothSocketIoThread who); @Override void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who); @Override void onDisconnected(String reason, BluetoothSocketIoThread who); }
BluetoothServerThread extends AbstractBluetoothThread implements BluetoothSocketIoThread.Listener { @Override public void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who) { final long threadId = who.getId(); Log.d(TAG, "onBytesWritten: " + size + " bytes successfully written (thread ID: " + threadId + ")"); if (who.getPeerProperties() != null) { Log.d(TAG, "onBytesWritten: Peer props = " + who.getPeerProperties().toString()); } boolean threadRemoved = removeThreadFromList(who, false); if (threadRemoved) { Log.d(TAG, "Handshake thread disposed (thread ID: " + threadId + ")"); } else { Log.e(TAG, "Failed to find the thread from the list (thread ID: " + threadId + ")"); } Log.d(TAG, "onIncomingConnectionConnected socket:" + who.getSocket() + ", properties: " + who.getPeerProperties()); mListener.onIncomingConnectionConnected(who.getSocket(), who.getPeerProperties()); } BluetoothServerThread(
            Listener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString); @Override void run(); @Override synchronized void shutdown(); @Override void onBytesRead(byte[] bytes, int size, BluetoothSocketIoThread who); @Override void onBytesWritten(byte[] bytes, int size, BluetoothSocketIoThread who); @Override void onDisconnected(String reason, BluetoothSocketIoThread who);  }