FilesystemFacadeImpl implements IFilesystemFacade { @Override public Collection<IPath> listFiles(final IPath directory, final IPathFilter filter) throws IOException { File dir = new File(directory.getPath()); if (!dir.isDirectory()) { throw new NotDirectoryException(directory.getPath()); } File[] files = dir.listFiles(file -> file.isFile() && filter.accept(new Path(file))); IPath[] paths = new IPath[files.length]; for (int i = 0; i < files.length; i++) { paths[i] = new Path(files[i]); } return Arrays.asList(paths); }  @Override Collection<IPath> listSubdirectories(final IPath directory); @Override Collection<IPath> listFiles(final IPath directory, final IPathFilter filter); @Override IPath joinPaths(final IPath first, final IPath... rest); @Override String readToString(final IPath path);  }
@Test(expected = NotDirectoryException.class) public void Should_listFiles_throwWhenFileIsNotADirectory() throws Exception { IPath path = new Path(Files.createTempFile("not-a-directory-", "")); filesystemFacade.listFiles(path, p -> true); }
@Test public void Should_listFiles_listFilesMatchingGivenFilter() throws Exception { java.nio.file.Path dirPath = Files.createTempDirectory("directory-with-files-"); Files.createDirectory(dirPath.resolve("1a")); Files.createFile(dirPath.resolve("2a")); Files.createFile(dirPath.resolve("b")); Collection<IPath> paths = filesystemFacade.listFiles( new Path(dirPath), path -> path.getPath().endsWith("a")); assertNotNull(paths); assertEquals(1, paths.size()); assertEquals(dirPath.resolve("2a").toString(), paths.iterator().next().getPath()); }