### Question:
TemperatureMeasurementDataCallback extends ProfileReadResponse implements TemperatureMeasurementCallback { @Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { super.onDataReceived(device, data); if (data.size() < 5) { onInvalidDataReceived(device, data); return; } int offset = 0; final int flags = data.getIntValue(Data.FORMAT_UINT8, offset); final int unit = (flags & 0x01) == UNIT_C ? UNIT_C : UNIT_F; final boolean timestampPresent = (flags & 0x02) != 0; final boolean temperatureTypePresent = (flags & 0x04) != 0; offset += 1; if (data.size() < 5 + (timestampPresent ? 7 : 0) + (temperatureTypePresent ? 1 : 0)) { onInvalidDataReceived(device, data); return; } final float temperature = data.getFloatValue(Data.FORMAT_FLOAT, 1); offset += 4; Calendar calendar = null; if (timestampPresent) { calendar = DateTimeDataCallback.readDateTime(data, offset); offset += 7; } Integer type = null; if (temperatureTypePresent) { type = data.getIntValue(Data.FORMAT_UINT8, offset); } onTemperatureMeasurementReceived(device, temperature, unit, calendar, type); } TemperatureMeasurementDataCallback(); protected  TemperatureMeasurementDataCallback(final Parcel in); @Override void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data);  }### Answer:
@Test public void onTemperatureMeasurementReceived() { final ProfileReadResponse response = new TemperatureMeasurementDataCallback() { @Override public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device, final float temperature, final int unit, @Nullable final Calendar calendar, @Nullable final Integer type) { called = true; assertEquals("Temperature", 37.60f, temperature, 0.001f); assertEquals("Unit", TemperatureMeasurementCallback.UNIT_C, unit); assertNotNull("Calendar present", calendar); assertTrue("Year set", calendar.isSet(Calendar.YEAR)); assertEquals("Year", calendar.get(Calendar.YEAR), 2012); assertTrue("Month set", calendar.isSet(Calendar.MONTH)); assertEquals("Month", calendar.get(Calendar.MONTH), Calendar.DECEMBER); assertTrue("Day set", calendar.isSet(Calendar.DATE)); assertEquals("Day", 5, calendar.get(Calendar.DATE)); assertEquals("Hour", 11, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals("Minute", 50, calendar.get(Calendar.MINUTE)); assertEquals("Seconds", 27, calendar.get(Calendar.SECOND)); assertEquals("Milliseconds", 0, calendar.get(Calendar.MILLISECOND)); assertNotNull("Type present", type); assertEquals(TemperatureMeasurementCallback.TYPE_FINGER, type.intValue()); } }; final Data data = new Data(new byte[] { 0x06, (byte) 0xB0, 0x0E, 0x00, (byte) 0xFE, (byte) 0xDC, 0x07, 0x0C, 0x05, 0x0B, 0x32, 0x1B, 0x04 }); called = false; response.onDataReceived(null, data); assertTrue(called); assertTrue(response.isValid()); }
@Test public void onInvalidDataReceived() { final ProfileReadResponse response = new TemperatureMeasurementDataCallback() { @Override public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device, final float temperature, final int unit, @Nullable final Calendar calendar, @Nullable final Integer type) { called = true; } }; final Data data = new Data(new byte[] { 0x06, (byte) 0xB0, 0x0E, 0x00, (byte) 0xFE, (byte) 0xDC, 0x07, 0x0C, 0x05, 0x0B, 0x32, 0x1B }); called = false; response.onDataReceived(null, data); assertFalse(called); assertFalse(response.isValid()); }