DaemonOperation extends Operation { private DaemonOperationResult executeAdd() throws Exception { for (String watchRoot : options.getWatchRoots()) { File watchRootFolder = new File(watchRoot); File watchRootAppFolder = new File(watchRootFolder, Config.DIR_APPLICATION); if (!watchRootFolder.isDirectory() || !watchRootAppFolder.isDirectory()) { throw new Exception("Given argument is not an existing folder, or a valid Syncany folder: " + watchRoot); } } for (String watchRoot : options.getWatchRoots()) { DaemonConfigHelper.addFolder(new File(watchRoot)); } loadOrCreateConfig(); int watchedMatchingFoldersCount = countWatchedMatchingFolders(); if (watchedMatchingFoldersCount == options.getWatchRoots().size()) { return new DaemonOperationResult(DaemonResultCode.OK, daemonConfig.getFolders()); } else if (watchedMatchingFoldersCount > 0) { return new DaemonOperationResult(DaemonResultCode.OK_PARTIAL, daemonConfig.getFolders()); } else { return new DaemonOperationResult(DaemonResultCode.NOK, 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 testExecuteAdd() throws Exception { when(options.getAction()).thenReturn(DaemonAction.ADD); 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()); assertEquals(1, res.getWatchList().size()); assertEquals(tempWatchRootAppFolder.getParentFile().getAbsolutePath(), res.getWatchList().get(0).getPath()); }