MuseHandler implements Closeable { void setConnectionListener() { this.connListener = new MuseConnectionListener() { @Override public void receiveMuseConnectionPacket(MuseConnectionPacket museConnectionPacket) { MuseHandler.this.bus.post(museConnectionPacket.getCurrentConnectionState()); } }; this.muse.registerConnectionListener(this.connListener); } MuseHandler(Muse muse, @NonNull EventBus bus); void resetFocusState(); @Override void close();  }
@Test public void testSetConnectionListener() throws Exception { class StatusHolder{ ConnectionState state; @Subscribe public void updateState(ConnectionState state){ this.state=state; } } this.museHandler.setConnectionListener(); StatusHolder holder = new StatusHolder(); this.eventBus.register(holder); MuseConnectionPacket packet = PowerMockito.mock(MuseConnectionPacket.class); Mockito.when(packet.getCurrentConnectionState()).thenReturn(ConnectionState.CONNECTED); this.museHandler.getMuseConnectionListener().receiveMuseConnectionPacket(packet); assertEquals("The status gets propagated",holder.state,ConnectionState.CONNECTED); Mockito.when(packet.getCurrentConnectionState()).thenReturn(ConnectionState.CONNECTING); this.museHandler.getMuseConnectionListener().receiveMuseConnectionPacket(packet); assertEquals("The status gets propagated",holder.state,ConnectionState.CONNECTING); Mockito.when(packet.getCurrentConnectionState()).thenReturn(ConnectionState.DISCONNECTED); this.museHandler.getMuseConnectionListener().receiveMuseConnectionPacket(packet); assertEquals("The status gets propagated",holder.state,ConnectionState.DISCONNECTED); }