ResourceHelper { public static Stream<String> getResourcesFromDirectory(File directory, Pattern pattern) { if (directory == null || directory.listFiles() == null) { return Stream.empty(); } return Arrays.stream(directory.listFiles()).flatMap(elem -> { if (elem.isDirectory()) { return getResourcesFromDirectory(elem, pattern); } else { try { String fileName = elem.getCanonicalPath(); if (pattern.matcher(fileName).matches()) { return Stream.of(fileName); } } catch (final IOException e) { throw new ScenarioException("Impossible to access to resources", e); } } return Stream.empty(); }); } private  ResourceHelper(); static Stream<String> getResourcesByExtension(String extension); static Stream<String> getResourcesFromDirectory(File directory, Pattern pattern);  }
@Test public void getResourcesFromDirectoryTest() { List<String> classPathElements = Arrays.asList(getClassPathElements()); Optional<String> testFolder = classPathElements.stream().filter(elem -> elem.contains("test-classes")).findFirst(); assertTrue(testFolder.isPresent()); File dir = new File(testFolder.get()); List<String> filesFound = getResourcesFromDirectory(dir, Pattern.compile(".*testFile.txt")) .collect(Collectors.toList()); assertEquals(1, filesFound.size()); assertEquals(0, getResourcesFromDirectory(null, null).count()); assertEquals(0, getResourcesFromDirectory(dir, Pattern.compile("noMatch")).count()); }