protected List<Document> loadTestDocuments(String pathOnClasspath) { List<Document> results = new ArrayList<>(); try (InputStream stream = Testing.Files.readResourceAsStream(pathOnClasspath);) { assertThat(stream).isNotNull(); IoUtil.readLines(stream, line -> { Document doc = Document.parse(line); assertThat(doc.size()).isGreaterThan(0); results.add(doc); }); } catch (IOException e) { fail("Unable to find or read file '" + pathOnClasspath + "': " + e.getMessage()); } return results; }
/** * Read a classpath resource into a string. * * @param pathOnClasspath the path of the resource on the classpath * @return the string representation */ public static String readResourceAsString(String pathOnClasspath) { try (InputStream stream = readResourceAsStream(pathOnClasspath)) { return IoUtil.read(stream); } catch (IOException e) { Fail.fail("Unable to read '" + pathOnClasspath + "'", e); return null; } }
/** * Obtain an InputStream to a named resource on the classpath used to load this {@link Testing} class. * * @param pathOnClasspath the path of the resource on the classpath * @return the string representation */ public static InputStream readResourceAsStream(String pathOnClasspath) { return readResourceAsStream(pathOnClasspath, Testing.class); }