### Question:
FileSystemCallbackHandlerDao implements CallbackHandlerDao { @Override public List<PersistentFileHandler> findAll() { try (final Stream<Path> pathStream = Files.list(Paths.get(configuration.getHandlerDirectory()))) { return pathStream.map(this::toPersistentFileHandler) .filter(Optional::isPresent) .map(Optional::get) .collect(toList()); } catch (IOException e) { log.error("Can not restore handlers due to: {}", e.getMessage(), e); } return Collections.emptyList(); }  @Override void upsert(PersistentFileHandler handlerCallback); @Override List<PersistentFileHandler> findAll(); @Override void remove(String handlerId);  }### Answer:
@Test public void findAll() throws IOException { final File handler1 = getHandlerFile("test1.json"); final File handler2 = getHandlerFile("test2.json"); final String handlersFolder = getHandlersFolder(); when(configuration.getHandlerDirectory()).thenReturn(handlersFolder); final PersistentFileHandler persistentFileHandler1 = new PersistentFileHandler(null, 1L, "/opt"); final PersistentFileHandler persistentFileHandler2 = new PersistentFileHandler(null, 2L, "/opt"); when(mapper.readValue(any(File.class), Matchers.<Class<PersistentFileHandler>>any())).thenReturn (persistentFileHandler1).thenReturn(persistentFileHandler2); final List<PersistentFileHandler> handlers = fileSystemCallbackHandlerDao.findAll(); assertEquals(2, handlers.size()); verify(configuration).getHandlerDirectory(); verify(mapper).readValue(handler1, PersistentFileHandler.class); verify(mapper).readValue(handler2, PersistentFileHandler.class); verifyNoMoreInteractions(mapper, dao, configuration); }
@Test public void findAllWithException() throws IOException { new File(getHandlersFolder()).delete(); when(configuration.getHandlerDirectory()).thenReturn(getHandlersFolder()); when(mapper.readValue(any(File.class), Matchers.<Class<PersistentFileHandler>>any())).thenThrow(new RuntimeException("Exception")); final List<PersistentFileHandler> handlers = fileSystemCallbackHandlerDao.findAll(); assertEquals(0, handlers.size()); verify(configuration).getHandlerDirectory(); verifyNoMoreInteractions(mapper, dao, configuration); }
@Test public void findAllWithOneWrongHandlerFile() throws IOException { final File handler1 = getHandlerFile("test1.json"); final File handler2 = getHandlerFile("test2.json"); final String handlersFolder = getHandlersFolder(); final PersistentFileHandler persistentFileHandler1 = new PersistentFileHandler(null, 1L, "/opt"); when(configuration.getHandlerDirectory()).thenReturn(handlersFolder); when(mapper.readValue(any(File.class), Matchers.<Class<PersistentFileHandler>>any())).thenReturn (persistentFileHandler1).thenThrow(new RuntimeException("Exception")); final List<PersistentFileHandler> handlers = fileSystemCallbackHandlerDao.findAll(); assertEquals(1, handlers.size()); verify(configuration).getHandlerDirectory(); verify(mapper).readValue(handler1, PersistentFileHandler.class); verify(mapper).readValue(handler2, PersistentFileHandler.class); verifyNoMoreInteractions(mapper, dao, configuration); }