### Question:
HumidityNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float temperature = decodeTemperature(bytes[1], bytes[0]); float humidity = decodeHumidity(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(HUMIDITY_VALUE_ID, humidity, TEMPERATURE_VALUE_ID, temperature)); processor.onNext(sensorLog); } HumidityNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); static final String HUMIDITY_VALUE_ID; static final String TEMPERATURE_VALUE_ID; }### Answer:
@Test public void producesValidSensorLog() { Faker faker = new Faker(); double humidity = faker.number().randomDouble(4, 0, 50); int humidityNorm = (int)(humidity * 65536 / 100); double temperature = faker.number().randomDouble(4, -50, 50); int temperatureNorm = (int)((temperature + 40) / 165 * 65536); SensorConfig config = new SensorConfig("someId", "sensortag", null); ReplayProcessor<SensorLog> processor = ReplayProcessor.create(10); HumidityNotification notification = new HumidityNotification(config, processor); notification.run(new byte[] { (byte)(temperatureNorm & 0xff), (byte)(temperatureNorm >> 8), (byte)(humidityNorm & 0xff), (byte)(humidityNorm >> 8) }); SensorLog createdLog = processor.blockingFirst(); assertThat(createdLog).isNotNull(); assertThat(createdLog.getSensorId()).matches(config.getId()); assertThat(createdLog.getAttributeValue()).containsKey(HumidityNotification.HUMIDITY_VALUE_ID); assertThat(createdLog.getAttributeValue()).containsKey(HumidityNotification.TEMPERATURE_VALUE_ID); assertThat((float)createdLog.getAttributeValue().get(HumidityNotification.HUMIDITY_VALUE_ID)).isWithin(0.1f).of((float)humidity); assertThat((float)createdLog.getAttributeValue().get(HumidityNotification.TEMPERATURE_VALUE_ID)).isWithin(0.1f).of((float)temperature); }