@Test public void testOnCharacteristicRead() { BluetoothGattCharacteristic otherCharacteristic = Mockito.mock(BluetoothGattCharacteristic.class); when(otherCharacteristic.getUuid()).thenReturn(Neatle.createUUID(123)); when(gatt.getService(eq(serviceUUID))).thenReturn(gattService); when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic); when(gatt.readCharacteristic(eq(gattCharacteristic))).thenReturn(true); when(gattCharacteristic.getValue()).thenReturn(new byte[]{21, 22}); when(gattCharacteristic.getUuid()).thenReturn(characteristicUUID); readCommand.execute(device, operationCommandObserver, gatt); readCommand.onCharacteristicRead(gatt, otherCharacteristic, BluetoothGatt.GATT_SUCCESS); verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class)); verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class)); Mockito.reset(commandObserver, operationCommandObserver); readCommand.onCharacteristicRead(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS); CommandResult result = CommandResult.createCharacteristicRead(gattCharacteristic, BluetoothGatt.GATT_SUCCESS); verify(commandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); verify(operationCommandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); }
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (!characteristic.getUuid().equals(characteristicUUID)) { NeatleLogger.e("Got a read request for a unknown characteristic"); return; } CommandResult result = CommandResult.createCharacteristicRead(characteristic, status); NeatleLogger.d("Read: " + result); finish(result); }
ReadCommand extends SingleCharacteristicsCommand { public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (!characteristic.getUuid().equals(characteristicUUID)) { NeatleLogger.e("Got a read request for a unknown characteristic"); return; } CommandResult result = CommandResult.createCharacteristicRead(characteristic, status); NeatleLogger.d("Read: " + result); finish(result); } }
ReadCommand extends SingleCharacteristicsCommand { public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (!characteristic.getUuid().equals(characteristicUUID)) { NeatleLogger.e("Got a read request for a unknown characteristic"); return; } CommandResult result = CommandResult.createCharacteristicRead(characteristic, status); NeatleLogger.d("Read: " + result); finish(result); } ReadCommand(UUID serviceUUID, UUID characteristicUUID, CommandObserver observer); }
ReadCommand extends SingleCharacteristicsCommand { public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (!characteristic.getUuid().equals(characteristicUUID)) { NeatleLogger.e("Got a read request for a unknown characteristic"); return; } CommandResult result = CommandResult.createCharacteristicRead(characteristic, status); NeatleLogger.d("Read: " + result); finish(result); } ReadCommand(UUID serviceUUID, UUID characteristicUUID, CommandObserver observer); void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status); @Override String toString(); }
ReadCommand extends SingleCharacteristicsCommand { public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (!characteristic.getUuid().equals(characteristicUUID)) { NeatleLogger.e("Got a read request for a unknown characteristic"); return; } CommandResult result = CommandResult.createCharacteristicRead(characteristic, status); NeatleLogger.d("Read: " + result); finish(result); } ReadCommand(UUID serviceUUID, UUID characteristicUUID, CommandObserver observer); void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status); @Override String toString();  }