HdfsServiceImpl implements HdfsService { @Override public List<String> list(Path path) throws RestException { try { return Arrays.asList(getFileSystem().listStatus(path)).stream().map(fileStatus -> fileStatus.getPath().getName()).collect(Collectors.toList()); } catch (IOException e) { throw new RestException(e); } } @Autowired  HdfsServiceImpl(Configuration configuration); @Override List<String> list(Path path); @Override String read(Path path); @Override void write(Path path, byte[] contents, String userMode, String groupMode, String otherMode); @Override boolean delete(Path path, boolean recursive); @Override boolean mkdirs(Path path);  }
@Test public void listShouldListFiles() throws Exception { FileUtils.writeStringToFile(new File(testDir, "file1.txt"), "value1"); FileUtils.writeStringToFile(new File(testDir, "file2.txt"), "value2"); List<String> paths = hdfsService.list(new Path(testDir)); Collections.sort(paths); assertEquals(2, paths.size()); assertEquals("file1.txt", paths.get(0)); assertEquals("file2.txt", paths.get(1)); }