MediaManagerImpl implements MediaManager { @Subscribe public void handleMediaEvent(final MediaEvent mediaEvent) { if (mediaEvent.getType() == SCAN_NODE) { getNode(mediaEvent.getParameter()).ifPresent(this::scanNode); } else { LOGGER.error("Unknown media event {}", mediaEvent); } } @Inject  MediaManagerImpl(final ConfigurationManager configurationManager, final ResourceBundle resourceBundle, final MediaDao mediaDao,
                            final MimeTypeManager mimeTypeManager, @Named("localAddress") final InetAddress localAddress); @Override Optional<MediaNode> getNode(final String nodeId); @Override String getNodeUrl(final MediaNode node); @Override Collection<MediaNode> searchChildNodes(final MediaSearchRequest request); @Override void cleanUpCache(); @Subscribe void handleMediaEvent(final MediaEvent mediaEvent);  }
@Test public void testHandleMediaEvent() { ConfigurationDao configurationDao = new TestConfigurationDao(); ConfigurationManager configurationManager = new ConfigurationManagerImpl(configurationDao); ResourceBundle resourceBundle = ResourceBundle.getBundle("message"); MediaDao mediaDao = createMock(MediaDao.class); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); InetAddress localAddress = createMock(InetAddress.class); expect(mediaDao.getRootNodeChildren(eq(VIDEO))).andReturn(getRootChildNodes(VIDEO, configurationDao)); expect(mediaDao.getChildNodes(eq("videosTest"))).andReturn(new ArrayList<>()); replay(mediaDao, mimeTypeManager, localAddress); MediaManagerImpl mediaManager = new MediaManagerImpl(configurationManager, resourceBundle, mediaDao, mimeTypeManager, localAddress); MediaEvent mediaEvent = new MediaEvent(SCAN_NODE, VIDEO.getId()); mediaManager.handleMediaEvent(mediaEvent); verify(mediaDao, mimeTypeManager, localAddress); }
@Test public void testHandleBadMediaEvent() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); ResourceBundle resourceBundle = ResourceBundle.getBundle("message"); MediaDao mediaDao = createMock(MediaDao.class); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); InetAddress localAddress = createMock(InetAddress.class); replay(mediaDao, mimeTypeManager, localAddress); MediaManagerImpl mediaManager = new MediaManagerImpl(configurationManager, resourceBundle, mediaDao, mimeTypeManager, localAddress); MediaEvent mediaEvent = new MediaEvent(UNKNOWN, VIDEO.getId()); mediaManager.handleMediaEvent(mediaEvent); verify(mediaDao, mimeTypeManager, localAddress); }