CommonExcelResourcesLocator { public static Resource[] getResources(Resource source, Resource destination) throws IOException { List<Resource> resourceList = new ArrayList<>(); Path sourcePath = source.getFile().toPath(); Path destinationPath = destination.getFile().toPath(); try (Stream<Path> stream1 = Files.list(sourcePath)) { stream1.filter(path1 -> { boolean result = false; try (Stream<Path> stream2 = Files.list(destinationPath)) { result = stream2 .filter(path2 -> path2.getFileName() != null) .anyMatch(path2 -> path2.getFileName().equals(path1.getFileName())); } catch (IOException e) { LOGGER.error("Cannot list this directory", e); } return result; }).forEach(path -> resourceList.add(new FileSystemResource(path.toFile()))); } return resourceList.toArray(new Resource[resourceList.size()]); }  static Resource[] getResources(Resource source, Resource destination);  }
@Test public void testGetResources() throws IOException { Assert.assertEquals(3, Files.list(SOURCE_PATH).count()); Assert.assertEquals(4, Files.list(DESTINATION_PATH).count()); Resource[] result = CommonExcelResourcesLocator.getResources(new FileSystemResource(SOURCE_PATH.toFile()), new FileSystemResource(DESTINATION_PATH.toFile())); Assert.assertEquals(2, result.length); }
@Test(expected = AssertionError.class) @Ignore public void testAssertion() throws IOException { CommonExcelResourcesLocator.getResources(new FileSystemResource(PATHS[0].toFile()), new FileSystemResource(DESTINATION_PATH.toFile())); }