SoundSystem extends BaseOpenMessage { static boolean isOn(OpenMessage request, List<OpenMessage> responses) { final String responseOnBaseBand = format(FORMAT_PREFIX_RESPONSE, WHO_16, ON_SOURCE_BASE_BAND); final String responseOnStereo = format(FORMAT_PREFIX_RESPONSE, WHO_16, ON_SOURCE_STEREO_CHANNEL); List<OpenMessage> validResponses = FluentIterable.from(responses) .filter(response -> (response.getValue().startsWith(responseOnBaseBand) || response.getValue().startsWith(responseOnStereo)) && !request.getValue().equals(requestStatus("0", Type.AMPLIFIER_GENERAL).getValue()) ).toList(); return validResponses.size() >= 1; } protected  SoundSystem(String value); static SoundSystem requestTurnOn(String where, Type type, Source source); static SoundSystem requestTurnOff(String where, Type type, Source source); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static SoundSystem requestStatus(String where, Type type); static Func1<OpenSession, OpenSession> handleStatus(Action0 onStatus, Action0 offStatus); static SoundSystem requestVolumeUp(String where, Type type); static SoundSystem requestVolumeDown(String where, Type type); static SoundSystem requestStationUp(String where, Type type); static SoundSystem requestStationDown(String where, Type type);  }
@Test public void testIsOn() { final String WHERE = "88"; OpenMessage request = requestStatus(WHERE, Type.AMPLIFIER_P2P); assertFalse("should be off", isOn(request, Lists.newArrayList())); assertFalse("should be off", isOn(request, asList(() -> ""))); assertFalse("should be off", isOn(request, asList(() -> ACK))); assertFalse("should be off", isOn(request, asList(requestStatus("0", Type.AMPLIFIER_GENERAL), () -> ACK))); assertTrue("should be on", isOn(request, asList(requestTurnOn(WHERE, Type.AMPLIFIER_P2P, Source.STEREO_CHANNEL)))); assertTrue("should be on", isOn(request, asList(requestTurnOn(WHERE, Type.AMPLIFIER_P2P, Source.STEREO_CHANNEL), () -> ""))); assertTrue("should be on", isOn(request, asList(requestTurnOn(WHERE, Type.AMPLIFIER_P2P, Source.BASE_BAND)))); assertTrue("should be on", isOn(request, asList(requestTurnOn(WHERE, Type.AMPLIFIER_P2P, Source.BASE_BAND), () -> ""))); }