ByteArrayResource implements Resource { @Override public InputStream getResourceAsStream(String location) { InputStream result = null; if (location != null && location.equals(this.location)) { result = new ByteArrayInputStream(bytes); } return result; } ByteArrayResource(String location, byte[] bytes); @Override Stream<String> getAllLocations(); byte[] getBytes(); @Override URL getResource(String location); @Override InputStream getResourceAsStream(String location);  }
@Test void testGetResourceAsStream() { ByteArrayResource resource = new ByteArrayResource("mylocation", new byte[0]); assertTrue(resource.getResourceAsStream("mylocation") instanceof ByteArrayInputStream); assertNull(resource.getResourceAsStream("notmylocation")); }