MuseHandler implements Closeable { void setBatteryListener() { this.batteryListener = new MuseDataListener() { @Override public void receiveMuseDataPacket(MuseDataPacket museDataPacket) { if (museDataPacket.getPacketType() == MuseDataPacketType.BATTERY) { double value = museDataPacket.getValues().get(Battery.CHARGE_PERCENTAGE_REMAINING.ordinal()); MuseHandler.this.bus.post(new BatteryReading(value)); } } @Override public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket) { } }; this.muse.registerDataListener(this.batteryListener, MuseDataPacketType.BATTERY); } MuseHandler(Muse muse, @NonNull EventBus bus); void resetFocusState(); @Override void close();  }
@Test public void testSetBatteryListener() throws Exception { class LevelHolder{ double level; @Subscribe public void updateState(MuseHandler.BatteryReading reading){ this.level=reading.getLevel(); } } this.museHandler.setBatteryListener(); LevelHolder holder = new LevelHolder(); this.eventBus.register(holder); MuseDataPacket packet = PowerMockito.mock(MuseDataPacket.class); ArrayList<Double> values = new ArrayList<>(20); for (Battery b:Battery.values()){ values.add(0.); } values.set(Battery.CHARGE_PERCENTAGE_REMAINING.ordinal(), 40.5); Mockito.when(packet.getPacketType()).thenReturn(MuseDataPacketType.BATTERY); Mockito.when(packet.getValues()).thenReturn(values); this.museHandler.getBatteryListener().receiveMuseDataPacket(packet); assertEquals("The battery is propagated",40.5,holder.level,0.0); }