BackendManagerImpl implements BackendManager { @Override public void editFolder(final String id, final ConfigurationFolder folder, final RootNode rootNode) { validateFolder(folder, rootNode, id); try { configurationManager.editNode(rootNode, id, folder.getName(), folder.getPath()) .ifPresent(node -> eventBus.post(new ConfigurationEvent(UPDATE_FOLDER, node, rootNode))); } catch (IOException e) { throw new BackendException(e); } catch (UnknownNodeException e) { throw new BackendException(FOLDER_UNKNOWN_ERROR, e); } } @Inject  BackendManagerImpl(final ConfigurationManager configurationManager, final EventBus eventBus); @Override Collection<ConfigurationFolder> getFolders(final RootNode rootNode); @Override ConfigurationFolder getFolder(final String id, final RootNode rootNode); @Override void addFolder(final ConfigurationFolder folder, final RootNode rootNode); @Override void editFolder(final String id, final ConfigurationFolder folder, final RootNode rootNode); @Override void removeFolder(final String id, final RootNode rootNode); @Override Settings getSettings(); @Override void saveSettings(final Settings settings);  }
@Test(expected = BackendException.class) public void testEditFolderIOException() throws IOException, UnknownNodeException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); expect(configurationManager.findNode(AUDIO, "id", "editedAudiosTest", System.getProperty("java.io.tmpdir"))).andReturn(Optional.<ConfigurationNode>empty()); expect(configurationManager.editNode(AUDIO, "id", "editedAudiosTest", System.getProperty("java.io.tmpdir"))).andThrow(new IOException()); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.editFolder("id", new ConfigurationFolder("id", "editedAudiosTest", System.getProperty("java.io.tmpdir")), AUDIO); } finally { verify(configurationManager, eventBus); } }
@Test public void testEditFolder() throws IOException, UnknownNodeException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); expect(configurationManager.findNode(AUDIO, "id", "name", System.getProperty("java.io.tmpdir"))).andReturn(Optional.<ConfigurationNode>empty()); expect(configurationManager.editNode(AUDIO, "id", "name", System.getProperty("java.io.tmpdir"))).andReturn(Optional.of(new ConfigurationNode("id", "name", System.getProperty("java.io.tmpdir")))); eventBus.post(isA(ConfigurationEvent.class)); expectLastCall(); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.editFolder("id", new ConfigurationFolder("id", "name", System.getProperty("java.io.tmpdir")), AUDIO); } finally { verify(configurationManager, eventBus); } }
@Test(expected = BackendException.class) public void testEditBadFolder() throws IOException, UnknownNodeException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); expect(configurationManager.findNode(AUDIO, "bad_id", "editedAudiosTest", System.getProperty("java.io.tmpdir"))).andReturn(Optional.<ConfigurationNode>empty()); expect(configurationManager.editNode(AUDIO, "bad_id", "editedAudiosTest", System.getProperty("java.io.tmpdir"))).andThrow(new UnknownNodeException("bad_id")); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.editFolder("bad_id", new ConfigurationFolder("id", "editedAudiosTest", System.getProperty("java.io.tmpdir")), AUDIO); } finally { verify(configurationManager, eventBus); } }
@Test public void testEditFolderNotSaved() throws IOException, UnknownNodeException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); expect(configurationManager.findNode(AUDIO, "id", "name", System.getProperty("java.io.tmpdir"))).andReturn(Optional.<ConfigurationNode>empty()); expect(configurationManager.editNode(AUDIO, "id", "name", System.getProperty("java.io.tmpdir"))).andReturn(Optional.<ConfigurationNode>empty()); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.editFolder("id", new ConfigurationFolder("id", "name", System.getProperty("java.io.tmpdir")), AUDIO); } finally { verify(configurationManager, eventBus); } }