ConfigurationManagerImpl implements ConfigurationManager { @Override public Optional<ConfigurationNode> editNode(final RootNode rootNode, final String nodeId, final String label, final String path) throws IOException, UnknownNodeException { ConfigurationNode currentNode = getNode(rootNode, nodeId); if (!currentNode.getLabel().equals(label) || !currentNode.getPath().equals(path)) { currentNode.setLabel(label); currentNode.setPath(path); save(); return Optional.of(currentNode); } return Optional.empty(); } @Inject  ConfigurationManagerImpl(ConfigurationDao configurationDao); @Override List<ConfigurationNode> getNodes(final RootNode rootNode); @Override ConfigurationNode getNode(final RootNode rootNode, final String nodeId); @Override Optional<ConfigurationNode> findNode(final RootNode rootNode, final String excludedNodeId, final String label, final String path); @Override boolean addNode(final RootNode rootNode, final ConfigurationNode node); @Override Optional<ConfigurationNode> editNode(final RootNode rootNode, final String nodeId, final String label, final String path); @Override void save(); @Override ConfigurationNode removeNode(final String nodeId, final RootNode rootNode); @Override T getParameter(final ConfigurationParameter<T> parameter); @Override void setParameter(final ConfigurationParameter<T> parameter, final T value);  }
@Test public void testEditNode() throws IOException, UnknownNodeException { ConfigurationDao configurationDao = createMock(ConfigurationDao.class); ConfigurationNode newNode = new ConfigurationNode("nodeId", "label", "path"); ConfigurationNode oldNode = new ConfigurationNode("nodeId", "oldLabel", "oldPath"); expect(configurationDao.getNode(eq(ROOT), eq(newNode.getId()))).andReturn(oldNode); configurationDao.save(); expectLastCall(); replay(configurationDao); ConfigurationManager configurationManager = new ConfigurationManagerImpl(configurationDao); Optional<ConfigurationNode> result = configurationManager.editNode(ROOT, newNode.getId(), newNode.getLabel(), newNode.getPath()); assertNotNull(result); assertTrue(result.isPresent()); assertEquals(result.get(), newNode); verify(configurationDao); }