@Test public void testOpenWithExistingLocation() throws IOException { String data = "test data"; File file = File.createTempFile(FileSystemResourceLoaderTest.class.getSimpleName(), ".data"); InputStream inputStream = null; try { FileUtils.write(file, data); inputStream = loader.openStream("file:" + file.getAbsolutePath()); String actualData = IOUtils.toString(inputStream); assertThat(actualData).isEqualTo(data); } finally { MiscUtils.closeQuietly(inputStream); file.delete(); } }
@Test(expected = IllegalArgumentException.class) public void testOpenWithEmptyLocation() throws IOException { loader.openStream(""); }
@Test public void testOpenWithNonExistentLocation() throws IOException { InputStream inputStream = loader.openStream("file:/test43243958438"); assertThat(inputStream).isNull(); }
@Test(expected = NullPointerException.class) public void testOpenWithNullLocation() throws IOException { loader.openStream(null); }
@Test(expected = IllegalArgumentException.class) public void testOpenWithInvalidSchema() throws IOException { loader.openStream("http:/tmp/test"); }
@Test(expected = IllegalArgumentException.class) public void testOpenWithInvalidLocation() throws IOException { loader.openStream("file/tmp/test"); }