AirplayStreamerImpl extends DeviceStreamer<AirplayDevice> { @Override public void play(final AirplayDevice device, final String contentUrl, final MediaNode node) { controlPoint.execute(device, new PlayCommand(contentUrl, 0d, newCommandFailureHandler(PLAY, device)) { @Override public void success(Map<String, String> contentParameters) { sendSuccess(PLAY, device.getId()); } }); } @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 testPlaySuccess() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); command.success(new HashMap<>(0)); }; AirplayDevice device = createMock(AirplayDevice.class); MediaNode node = createMock(AbstractNode.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id"); replay(eventBus, device, node); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.play(device, "ContentUrl", node); assertEquals(PLAY, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertTrue(captureStreamingEvent.getValue().isSuccess()); verify(eventBus, device, node); }
@Test public void testPlayFailure() { EventBus eventBus = createMock(EventBus.class); ControlPoint controlPoint = (device, command) -> { assertNotNull(command.getRequest()); command.failure("errorMessage"); }; AirplayDevice device = createMock(AirplayDevice.class); MediaNode node = createMock(AbstractNode.class); Capture<StreamingEvent> captureStreamingEvent = newCapture(); eventBus.post(capture(captureStreamingEvent)); expectLastCall().atLeastOnce(); expect(device.getId()).andReturn("id"); replay(eventBus, device, node); AirplayStreamerImpl streamer = new AirplayStreamerImpl(eventBus, controlPoint); streamer.play(device, "ContentUrl", node); assertEquals(PLAY, captureStreamingEvent.getValue().getType()); assertEquals("id", captureStreamingEvent.getValue().getDeviceId()); assertFalse(captureStreamingEvent.getValue().isSuccess()); assertEquals("errorMessage", captureStreamingEvent.getValue().getErrorMessage()); verify(eventBus, device, node); }