@Test public void nonExistentResourceThrowsExceptionWhenTryingToGetInputStream() { ClasspathResource resource = new ClasspathResource("foobar", ClasspathResourceTest.class); Exception e = assertThrows(FileNotFoundException.class, () -> resource.inputStream()); assertEquals("classpath:foobar", e.getMessage()); }
@Override public InputStream inputStream() throws FileNotFoundException { InputStream stream = classLoader.getResourceAsStream(this.path); if (stream == null) { throw new FileNotFoundException(CLASSPATH_SCHEME + path); } return stream; }
ClasspathResource implements Resource { @Override public InputStream inputStream() throws FileNotFoundException { InputStream stream = classLoader.getResourceAsStream(this.path); if (stream == null) { throw new FileNotFoundException(CLASSPATH_SCHEME + path); } return stream; } }
ClasspathResource implements Resource { @Override public InputStream inputStream() throws FileNotFoundException { InputStream stream = classLoader.getResourceAsStream(this.path); if (stream == null) { throw new FileNotFoundException(CLASSPATH_SCHEME + path); } return stream; } ClasspathResource(String path, Class<?> clazz);  ClasspathResource(String path, ClassLoader classLoader); }
ClasspathResource implements Resource { @Override public InputStream inputStream() throws FileNotFoundException { InputStream stream = classLoader.getResourceAsStream(this.path); if (stream == null) { throw new FileNotFoundException(CLASSPATH_SCHEME + path); } return stream; } ClasspathResource(String path, Class<?> clazz);  ClasspathResource(String path, ClassLoader classLoader); @Override String path(); @Override URL url(); @Override String absolutePath(); @Override InputStream inputStream(); @Override ClassLoader classLoader(); @Override String toString(); }
ClasspathResource implements Resource { @Override public InputStream inputStream() throws FileNotFoundException { InputStream stream = classLoader.getResourceAsStream(this.path); if (stream == null) { throw new FileNotFoundException(CLASSPATH_SCHEME + path); } return stream; } ClasspathResource(String path, Class<?> clazz);  ClasspathResource(String path, ClassLoader classLoader); @Override String path(); @Override URL url(); @Override String absolutePath(); @Override InputStream inputStream(); @Override ClassLoader classLoader(); @Override String toString(); static final String CLASSPATH_SCHEME; }