BackendManagerImpl implements BackendManager { @Override public void saveSettings(final Settings settings) { checkNonEmpty(settings.getServerName(), SETTINGS_SERVER_NAME_ERROR); configurationManager.setParameter(UPNP_SERVER_NAME, settings.getServerName()); try { configurationManager.save(); } catch (IOException e) { throw new BackendException(e); } eventBus.post(new ConfigurationEvent(SAVE_SETTINGS)); } @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 public void testSaveSettings() throws IOException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); configurationManager.setParameter(UPNP_SERVER_NAME, "holmes"); expectLastCall(); configurationManager.save(); expectLastCall(); eventBus.post(isA(ConfigurationEvent.class)); expectLastCall(); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.saveSettings(new Settings("holmes")); } finally { verify(configurationManager, eventBus); } }
@Test(expected = BackendException.class) public void testSaveSettingsWithoutServerName() { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.saveSettings(new Settings(null)); } finally { verify(configurationManager, eventBus); } }
@Test(expected = BackendException.class) public void testSaveSettingsIOException() throws IOException { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); configurationManager.setParameter(UPNP_SERVER_NAME, "holmes"); expectLastCall(); configurationManager.save(); expectLastCall().andThrow(new IOException()); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.saveSettings(new Settings("holmes")); } finally { verify(configurationManager, eventBus); } }
@Test(expected = BackendException.class) public void testSaveSettingsWithEmptyServerName() { ConfigurationManager configurationManager = createMock(ConfigurationManager.class); EventBus eventBus = createMock(EventBus.class); replay(configurationManager, eventBus); try { BackendManagerImpl backendManager = new BackendManagerImpl(configurationManager, eventBus); backendManager.saveSettings(new Settings("")); } finally { verify(configurationManager, eventBus); } }