AirplayStreamerImpl extends DeviceStreamer<AirplayDevice> { @Override public void updateStatus(final AirplayDevice device) { controlPoint.execute(device, new PlayStatusCommand(newCommandFailureHandler(STATUS, device)) { @Override public void success(Map<String, String> contentParameters) { if (contentParameters != null && !contentParameters.isEmpty()) { Long duration = getContentParameterValue(CONTENT_PARAMETER_DURATION, contentParameters); Long position = getContentParameterValue(CONTENT_PARAMETER_POSITION, contentParameters); sendSuccess(STATUS, device.getId(), duration, position); if (duration > 0 && position >= duration) { stop(device); } } } }); } @Inject  AirplayStreamerImpl(final EventBus eventBus, final ControlPoint controlPoint); @Override void play(final AirplayDevice device, final String contentUrl, final MediaNode node); @Override void stop(final AirplayDevice device); @Override void pause(final AirplayDevice device); @Override void resume(final AirplayDevice device); @Override void updateStatus(final AirplayDevice device);  }
@Test public void testUpdateStatusSuccessEmptyParameters() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); command.success(new HashMap<>()); }; AirplayDevice device = createMock(AirplayDevice.class); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); verify(eventBus, device); }
@Test public void testUpdateStatusSuccessNullParameters() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); command.success(null); }; AirplayDevice device = createMock(AirplayDevice.class); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); verify(eventBus, device); }
@Test public void testUpdateStatusSuccessWithParameters() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); Map<String, String> parameters = new HashMap<>(2); parameters.put("duration", "60"); parameters.put("position", "3"); command.success(parameters); }; AirplayDevice device = createMock(AirplayDevice.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id"); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); assertEquals(STATUS, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertTrue(captureStreamingEvent.getValue().isSuccess()); assertEquals(60l, captureStreamingEvent.getValue().getDuration().longValue()); assertEquals(3l, captureStreamingEvent.getValue().getPosition().longValue()); verify(eventBus, device); }
@Test public void testUpdateStatusSuccessWithStopParameters() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); Map<String, String> parameters = new HashMap<>(2); parameters.put("duration", "60"); parameters.put("position", "70"); command.success(parameters); }; AirplayDevice device = createMock(AirplayDevice.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id").atLeastOnce(); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); assertEquals(STOP, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertTrue(captureStreamingEvent.getValue().isSuccess()); verify(eventBus, device); }
@Test public void testUpdateStatusSuccessWithBadParameters() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); Map<String, String> parameters = new HashMap<>(2); parameters.put("bad_duration", "60"); parameters.put("bad_position", "70"); command.success(parameters); }; AirplayDevice device = createMock(AirplayDevice.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id").atLeastOnce(); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); assertEquals(STATUS, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertTrue(captureStreamingEvent.getValue().isSuccess()); verify(eventBus, device); }
@Test public void testUpdateStatusFailure() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); command.failure("errorMessage"); }; AirplayDevice device = createMock(AirplayDevice.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id"); replay(eventBus, device); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.updateStatus(device); assertEquals(STATUS, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertFalse(captureStreamingEvent.getValue().isSuccess()); assertEquals("errorMessage", captureStreamingEvent.getValue().getErrorMessage()); verify(eventBus, device); }