@Test public void testAsyncOnError() throws Exception { when(gatt.getService(eq(serviceUUID))).thenReturn(gattService); when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic); when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true); AsyncInputSource inputSource = Mockito.mock(AsyncInputSource.class); when(inputSource.nextChunk()).thenAnswer(new Answer<byte[]>() { @Override public byte[] answer(InvocationOnMock invocationOnMock) { writeCommand.onError(BluetoothGatt.GATT_FAILURE); return new byte[]{12, 21}; } }); writeCommand = new WriteCommand( serviceUUID, characteristicUUID, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT, inputSource, commandObserver); writeCommand.execute(device, operationCommandObserver, gatt); while (writeCommand.readerThread.isAlive()) { Robolectric.getForegroundThreadScheduler().advanceBy(0, TimeUnit.MILLISECONDS); Thread.yield(); } Robolectric.getForegroundThreadScheduler().advanceBy(0, TimeUnit.MILLISECONDS); verifyCommandFail(); verify(inputSource).close(); }
@Override protected void onError(int error) { NeatleLogger.e("Unexpected error while writing [" + error + "]"); finish(CommandResult.createErrorResult(characteristicUUID, error)); if (asyncMode && readerThread != null) { readerThread.interrupt(); } }
WriteCommand extends SingleCharacteristicsCommand { @Override protected void onError(int error) { NeatleLogger.e("Unexpected error while writing [" + error + "]"); finish(CommandResult.createErrorResult(characteristicUUID, error)); if (asyncMode && readerThread != null) { readerThread.interrupt(); } } }
WriteCommand extends SingleCharacteristicsCommand { @Override protected void onError(int error) { NeatleLogger.e("Unexpected error while writing [" + error + "]"); finish(CommandResult.createErrorResult(characteristicUUID, error)); if (asyncMode && readerThread != null) { readerThread.interrupt(); } } WriteCommand(UUID serviceUUID, UUID characteristicsUUID, int writeType, InputSource buffer, CommandObserver observer); }
WriteCommand extends SingleCharacteristicsCommand { @Override protected void onError(int error) { NeatleLogger.e("Unexpected error while writing [" + error + "]"); finish(CommandResult.createErrorResult(characteristicUUID, error)); if (asyncMode && readerThread != null) { readerThread.interrupt(); } } WriteCommand(UUID serviceUUID, UUID characteristicsUUID, int writeType, InputSource buffer, CommandObserver observer); @Override String toString(); }
WriteCommand extends SingleCharacteristicsCommand { @Override protected void onError(int error) { NeatleLogger.e("Unexpected error while writing [" + error + "]"); finish(CommandResult.createErrorResult(characteristicUUID, error)); if (asyncMode && readerThread != null) { readerThread.interrupt(); } } WriteCommand(UUID serviceUUID, UUID characteristicsUUID, int writeType, InputSource buffer, CommandObserver observer); @Override String toString();  }