DaemonOperation extends Operation { private DaemonOperationResult executeRemove() throws ConfigException { Collections.sort(options.getWatchRoots(), Ordering.natural().reverse()); for (String watchRoot : options.getWatchRoots()) { logger.log(Level.INFO, "- Removing folder from daemon config: " + watchRoot + " ..."); DaemonConfigHelper.removeFolder(watchRoot); } loadOrCreateConfig(); int watchedMatchingFoldersCount = countWatchedMatchingFolders(); if (watchedMatchingFoldersCount == options.getWatchRoots().size()) { return new DaemonOperationResult(DaemonResultCode.NOK, daemonConfig.getFolders()); } else if (watchedMatchingFoldersCount > 0) { return new DaemonOperationResult(DaemonResultCode.NOK_PARTIAL, daemonConfig.getFolders()); } else { return new DaemonOperationResult(DaemonResultCode.OK, daemonConfig.getFolders()); } } DaemonOperation();  DaemonOperation(DaemonOperationOptions options); @Override DaemonOperationResult execute(); @Subscribe void onControlCommand(ControlCommand controlCommand); @Subscribe void onControlManagementRequest(ControlManagementRequest controlRequest); static final String PID_FILE; }
@Test public void testExecuteRemove() throws Exception { when(options.getAction()).thenReturn(DaemonAction.REMOVE); List<String> watchRoots = new ArrayList<String>(); watchRoots.add(tempWatchRootAppFolder.getParent()); when(options.getWatchRoots()).thenReturn(watchRoots); DaemonOperationResult res = deamonOp.execute(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res.getResultCode()); assertNotNull(res.getWatchList()); assertTrue(res.getWatchList().isEmpty()); }