ResourceFileManager { public static Set<String> getMatchingResources(String location) { try { Path path = Paths.get(location); Path parentPath = path.getParent(); Path filenamePath = path.getFileName(); String parent = parentPath != null ? parentPath.toString() : ""; String filename = filenamePath != null ? filenamePath.toString() : ""; if (parent.equals("") || filename.equals("")) return Collections.emptySet(); Set<String> resources = getResourcePaths(parent); resources.removeIf(x -> !x.contains(filename)); for (String resource : resources) { log.debug("ResourceFileManager : Found file = {}", resource); } return resources; } catch (InvalidPathException ie) { log.info("Path could not be found: {}", ie.toString()); return Collections.emptySet(); } }  static Set<String> getResourcePaths(String path); static Set<String> getResourceFolders(String path); static boolean resourceExists(String location); static Set<String> getMatchingResources(String location);  }
@Test void canRetrieveAllMatchingFiles() { Set<String> result = ResourceFileManager.getMatchingResources("data/common/bear.jpg"); assert (result.size() == 1); }
@Test void receiveNullForInvalidPath() { Set<String> result = ResourceFileManager.getMatchingResources("wrongpath"); assert (result.size() == 0); }