StreamingHandler { @GET @Path("/stop/{deviceId}") @Produces(TEXT_PLAIN) public String stop(@PathParam("deviceId") final String deviceId) { try { streamingManager.stop(deviceId); } catch (UnknownDeviceException e) { LOGGER.error(e.getMessage(), e); return e.getMessage(); } return null; } @Inject  StreamingHandler(final MediaManager mediaManager, final StreamingManager streamingManager); @GET @Path("/devices") @Produces(APPLICATION_JSON) List<PlaybackDevice> getDevices(); @GET @Path("/play/{deviceId}/{contentId}") @Produces(TEXT_PLAIN) String play(@PathParam("deviceId") final String deviceId, @PathParam("contentId") final String contentId); @GET @Path("/pause/{deviceId}") @Produces(TEXT_PLAIN) String pause(@PathParam("deviceId") final String deviceId); @GET @Path("/stop/{deviceId}") @Produces(TEXT_PLAIN) String stop(@PathParam("deviceId") final String deviceId); @GET @Path("/resume/{deviceId}") @Produces(TEXT_PLAIN) String resume(@PathParam("deviceId") final String deviceId); @GET @Path("/status/{deviceId}") @Produces(APPLICATION_JSON) PlaybackStatus status(@PathParam("deviceId") final String deviceId); @GET @Path("/browse/{deviceId}/{nodeId}") @Produces(APPLICATION_JSON) DeviceBrowseResult browse(@PathParam("deviceId") final String deviceId, @PathParam("nodeId") final String nodeId);  }
@Test public void testStopOK() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); streamingManager.stop(eq("deviceId")); expectLastCall().atLeastOnce(); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); String result = streamingHandler.stop("deviceId"); assertNull(result); verify(mediaManager, streamingManager); }
@Test public void testStopKO() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); streamingManager.stop(eq("deviceId")); expectLastCall().andThrow(new UnknownDeviceException("deviceId")).atLeastOnce(); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); String result = streamingHandler.stop("deviceId"); assertNotNull(result); assertTrue(result.contains("deviceId")); verify(mediaManager, streamingManager); }