@Test public void producesValidSensorLog() { Faker faker = new Faker(); int red = faker.number().numberBetween(0, 32768); int green = faker.number().numberBetween(0, 32768); int blue = faker.number().numberBetween(0, 32768); int clear = faker.number().numberBetween(0, 32768); SensorConfig config = new SensorConfig("someId", "sensortag", null); ReplayProcessor<SensorLog> processor = ReplayProcessor.create(10); ColorNotification notification = new ColorNotification(config, processor); notification.run(new byte[] { (byte)red, (byte)(red >> 8), (byte)green, (byte)(green >> 8), (byte)blue, (byte)(blue >> 8), (byte)clear, (byte)(clear >> 8) }); SensorLog createdLog = processor.blockingFirst(); assertThat(createdLog).isNotNull(); assertThat(createdLog.getSensorId()).matches(config.getId()); assertThat(createdLog.getAttributeValue()).containsExactly( ColorNotification.COLOUR_RED_VALUE_ID, red, ColorNotification.COLOUR_GREEN_VALUE_ID, green, ColorNotification.COLOUR_BLUE_VALUE_ID, blue, ColorNotification.COLOUR_CLEAR_VALUE_ID, clear); }
@Override public void run(byte[] bytes) { int red = decodeColor(bytes[1], bytes[0]); int green = decodeColor(bytes[3], bytes[2]); int blue = decodeColor(bytes[5], bytes[4]); int clear = decodeColor(bytes[7], bytes[6]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(COLOUR_RED_VALUE_ID, red, COLOUR_GREEN_VALUE_ID, green, COLOUR_BLUE_VALUE_ID, blue, COLOUR_CLEAR_VALUE_ID, clear)); processor.onNext(sensorLog); }
ColorNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { int red = decodeColor(bytes[1], bytes[0]); int green = decodeColor(bytes[3], bytes[2]); int blue = decodeColor(bytes[5], bytes[4]); int clear = decodeColor(bytes[7], bytes[6]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(COLOUR_RED_VALUE_ID, red, COLOUR_GREEN_VALUE_ID, green, COLOUR_BLUE_VALUE_ID, blue, COLOUR_CLEAR_VALUE_ID, clear)); processor.onNext(sensorLog); } }
ColorNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { int red = decodeColor(bytes[1], bytes[0]); int green = decodeColor(bytes[3], bytes[2]); int blue = decodeColor(bytes[5], bytes[4]); int clear = decodeColor(bytes[7], bytes[6]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(COLOUR_RED_VALUE_ID, red, COLOUR_GREEN_VALUE_ID, green, COLOUR_BLUE_VALUE_ID, blue, COLOUR_CLEAR_VALUE_ID, clear)); processor.onNext(sensorLog); } ColorNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); }
ColorNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { int red = decodeColor(bytes[1], bytes[0]); int green = decodeColor(bytes[3], bytes[2]); int blue = decodeColor(bytes[5], bytes[4]); int clear = decodeColor(bytes[7], bytes[6]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(COLOUR_RED_VALUE_ID, red, COLOUR_GREEN_VALUE_ID, green, COLOUR_BLUE_VALUE_ID, blue, COLOUR_CLEAR_VALUE_ID, clear)); processor.onNext(sensorLog); } ColorNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); }
ColorNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { int red = decodeColor(bytes[1], bytes[0]); int green = decodeColor(bytes[3], bytes[2]); int blue = decodeColor(bytes[5], bytes[4]); int clear = decodeColor(bytes[7], bytes[6]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(COLOUR_RED_VALUE_ID, red, COLOUR_GREEN_VALUE_ID, green, COLOUR_BLUE_VALUE_ID, blue, COLOUR_CLEAR_VALUE_ID, clear)); processor.onNext(sensorLog); } ColorNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); static final String COLOUR_RED_VALUE_ID; static final String COLOUR_GREEN_VALUE_ID; static final String COLOUR_BLUE_VALUE_ID; static final String COLOUR_CLEAR_VALUE_ID; }