### Question:
FolderListener implements Runnable { public static WatchItem listen(String directoryName, FileHandlerCallback fileHandlerCallback, long timeoutMillis, long fileLengthCheckDelay, CallbackHandlerDao callbackHandlerDao) { return listen(directoryName, fileHandlerCallback, timeoutMillis, fileLengthCheckDelay, null, callbackHandlerDao); } private  FolderListener(); private  FolderListener(String directoryName, CallbackHandlerDao dao); static WatchItem listen(String directoryName, FileHandlerCallback fileHandlerCallback,
								   long timeoutMillis, long fileLengthCheckDelay,
								   CallbackHandlerDao callbackHandlerDao); static WatchItem listen(String directoryName, FileHandlerCallback fileHandlerCallback, long timeoutMillis,
								   long fileLengthCheckDelay, String fileName, CallbackHandlerDao callbackHandlerDao); static void terminateAll(); static List<FolderListener> getListeners(); boolean isAlive(); boolean isListen(); WatchItemList getItemList(); String getDirectoryName(); @Override void run(); static final long LISTENER_TIMEOUT_MILLLIS; static final long LISTENER_IDLE_TIMEOUT_MILLLIS; }### Answer:
@Test public void listen() throws InterruptedException, ExecutionException, IOException { Integer uuid = 1; FileHandlerCallback fHandler; WatchItem item; handleResult = false; fHandler = new FileHandler(uuid.toString()); item = FolderListener.listen(getDirectory(), fHandler, timeoutMillis, fileLengthCheckDelay, null); FolderListener listener = FolderListener.getListeners().get(0); assertEquals(false, listener.isListen()); assertEquals(true, listener.isAlive()); System.out.println("TEST process FALSE"); uuid = 2; createFile(uuid.toString()); fHandler = new FileHandler(uuid.toString()); item = FolderListener.listen(getDirectory(), fHandler, timeoutMillis, fileLengthCheckDelay, null); processFile(item); assertEquals(true, listener.isListen()); assertEquals(false, item.getFutureResultSync()); assertEquals(false, item.getFutureResult()); System.out.println("TEST process TRUE"); uuid = 3; handleResult = true; createFile(uuid.toString()); fHandler = new FileHandler(uuid.toString()); item = FolderListener.listen(getDirectory(), fHandler, timeoutMillis, fileLengthCheckDelay, null); processFile(item); assertEquals(true, item.getFutureResultSync()); assertEquals(true, item.getFutureResult()); System.out.println("TEST process with out listen"); uuid = 4; createFile(uuid.toString()); fHandler = new FileHandler(uuid.toString()); item = FolderListener.listen(getDirectory(), fHandler, timeoutMillis, fileLengthCheckDelay, getFileName(uuid .toString()), null); long expiredTime = System.currentTimeMillis() + maxWaitTimeoutMillis; while (item.getFuture() == null) { if (expiredTime < System.currentTimeMillis()) { throw new InterruptedException("Timeout has been expired"); } Thread.sleep(100); } assertEquals(true, item.getFutureResultSync()); assertEquals(true, item.getFutureResult()); FolderListener.terminateAll(); expiredTime = System.currentTimeMillis() + maxWaitTimeoutMillis; while (FolderListener.getListeners().size() > 0) { if (expiredTime < System.currentTimeMillis()) { throw new InterruptedException("Timeout has been expired"); } Thread.sleep(100); } System.out.println("All listen tests passed"); for (int i = 1; i <= uuid; i++) { removeFile(String.valueOf(i)); } }