StreamingManagerImpl implements StreamingManager { @Override public StreamingSession getSession(final String deviceId) throws UnknownSessionException { return sessionDao.getSession(deviceId); } @Inject  StreamingManagerImpl(final ConfigurationManager configurationManager, final DeviceDao deviceDao, final SessionDao sessionDao,
                                @Named("upnp") final DeviceStreamer upnpStreamer,
                                @Named("airplay") final DeviceStreamer airplayStreamer); @Override void addDevice(final Device device); @Override void removeDevice(final String deviceId); @Override Collection<Device> findDevices(final String hostAddress); @Override Collection<Device> getDevices(); @Override Device getDevice(final String deviceId); @Override StreamingSession getSession(final String deviceId); @Override @SuppressWarnings("unchecked") void play(final String deviceId, final String contentUrl, final MediaNode node); @Override @SuppressWarnings("unchecked") void stop(final String deviceId); @Override @SuppressWarnings("unchecked") void pause(final String deviceId); @Override @SuppressWarnings("unchecked") void resume(final String deviceId); @Subscribe void handleStreamingEvent(final StreamingEvent event);  }
@Test public void testGetSession() throws UnknownSessionException { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(sessionDao.getSession("deviceId")).andReturn(null); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.getSession("deviceId"); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test(expected = UnknownSessionException.class) public void testGetSessionUnknownDevice() throws UnknownSessionException { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(sessionDao.getSession("deviceId")).andThrow(new UnknownSessionException("deviceId")); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.getSession("deviceId"); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }