@Override public DaemonOperationResult execute() throws Exception { logger.log(Level.INFO, "Starting daemon operation with action " + options.getAction() + " ..."); switch (options.getAction()) { case LIST: return executeList(); case ADD: return executeAdd(); case REMOVE: return executeRemove(); case RUN: return executeRun(); default: throw new Exception("Unknown action: " + options.getAction()); } }
@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()); }
@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()); }
@Test public void testGetAction() { DaemonAction res = options.getAction(); assertNotNull(res); assertEquals(DaemonAction.ADD, res); }
@Test public void testExecuteList() throws Exception { when(options.getAction()).thenReturn(DaemonAction.LIST); DaemonOperationResult res = deamonOp.execute(); assertNotNull(res); assertEquals(DaemonResultCode.OK, res.getResultCode()); assertNotNull(res.getWatchList()); }