### Question:
BatteryLevelDataCallback extends ProfileReadResponse implements BatteryLevelCallback { @SuppressWarnings("ConstantConditions") @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { super.onDataReceived(device, data); if (data.size() == 1) { final int batteryLevel = data.getIntValue(Data.FORMAT_UINT8, 0); if (batteryLevel >= 0 && batteryLevel <= 100) { onBatteryLevelChanged(device, batteryLevel); return; } } onInvalidDataReceived(device, data); } BatteryLevelDataCallback(); protected  BatteryLevelDataCallback(final Parcel in); @SuppressWarnings("ConstantConditions") @Override void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data);  }### Answer:
@Test public void onBatteryLevelChanged_fullBattery() { final DataReceivedCallback callback = new BatteryLevelDataCallback() { @Override public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { assertEquals("Correct data", batteryLevel, 100); } @Override public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { assertEquals("Correct data reported as invalid", 1, 2); } }; final Data data = new Data(new byte[] { 0x64 }); callback.onDataReceived(null, data); }
@Test public void onBatteryLevelChanged_lowBattery() { final DataReceivedCallback callback = new BatteryLevelDataCallback() { @Override public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { assertEquals("Correct data", batteryLevel, 15); } @Override public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { assertEquals("Correct data reported as invalid", 1, 2); } }; final Data data = new Data(new byte[] { 0x0F }); callback.onDataReceived(null, data); }
@Test public void onInvalidDataReceived_dataTooLong() { final DataReceivedCallback callback = new BatteryLevelDataCallback() { @Override public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { assertEquals("Invalid date returned Battery Level", 1, 2); } @Override public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { assertEquals("Invalid data", data.size(), 2); } }; final Data data = new Data(new byte[] { 0x64, 0x00 }); callback.onDataReceived(null, data); }
@Test public void onInvalidDataReceived_batteryLevelOutOfRange() { final DataReceivedCallback callback = new BatteryLevelDataCallback() { @Override public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { assertEquals("Invalid date returned Battery Level", 1, 2); } @Override public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { assertEquals("Invalid data", data.size(), 1); } }; final Data data = new Data(new byte[] { 0x65 }); callback.onDataReceived(null, data); }