MuseHandler implements Closeable { void setFocusListener() { this.focusListener = new MuseDataListener() { @Override public void receiveMuseDataPacket(MuseDataPacket museDataPacket) { if (museDataPacket.getPacketType() == MuseDataPacketType.CONCENTRATION) { mConcentrationManager.addConcentrationValue(museDataPacket.getValues().get(0)); double value = mConcentrationManager.getConcentration(); MuseHandler.this.bus.post(new FocusReading(value)); } } @Override public void receiveMuseArtifactPacket(MuseArtifactPacket museArtifactPacket) { } }; this.muse.registerDataListener(this.focusListener, MuseDataPacketType.CONCENTRATION); } MuseHandler(Muse muse, @NonNull EventBus bus); void resetFocusState(); @Override void close();  }
@Test public void testSetFocusListener(){ class FocusHolder{ double focus; @Subscribe public void set(MuseHandler.FocusReading reading){ this.focus = reading.getFocus(); } } FocusHolder holder = new FocusHolder(); this.eventBus.register(holder); this.museHandler.setFocusListener(); MuseDataPacket packet = PowerMockito.mock(MuseDataPacket.class); ArrayList<Double> values = new ArrayList<>(1); values.add(1.5); Mockito.when(packet.getPacketType()).thenReturn(MuseDataPacketType.CONCENTRATION); Mockito.when(packet.getValues()).thenReturn(values); this.museHandler.getFocusListener().receiveMuseDataPacket(packet); assertEquals("The focus", holder.focus,1.5,0.); }