MediaManagerImpl implements MediaManager { @Override public Optional<MediaNode> getNode(final String nodeId) { Optional<MediaNode> node = Optional.empty(); RootNode rootNode = getById(nodeId); if (rootNode != NONE) { node = Optional.of(new FolderNode(rootNode.getId(), rootNode.getParentId(), resourceBundle.getString("rootNode." + rootNode.getId()))); } else if (nodeId != null) { node = mediaDao.getNode(nodeId); } return node; } @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 testGetNodeRoot() { 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); Optional<MediaNode> result = mediaManager.getNode(VIDEO.getId()); assertNotNull(result); assertTrue(result.isPresent()); verify(mediaDao, mimeTypeManager, localAddress); }
@Test public void testGetNode() { 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); expect(mediaDao.getNode(eq("nodeId"))).andReturn(Optional.of(new FolderNode("id", "parentId", "name"))); replay(mediaDao, mimeTypeManager, localAddress); MediaManagerImpl mediaManager = new MediaManagerImpl(configurationManager, resourceBundle, mediaDao, mimeTypeManager, localAddress); Optional<MediaNode> result = mediaManager.getNode("nodeId"); assertNotNull(result); assertTrue(result.isPresent()); verify(mediaDao, mimeTypeManager, localAddress); }
@Test public void testGetNodeNull() { 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); Optional<MediaNode> result = mediaManager.getNode(null); assertNotNull(result); assertFalse(result.isPresent()); verify(mediaDao, mimeTypeManager, localAddress); }