ArtifactFilesystem extends AbstractDbArtifact { @Override @SuppressWarnings("squid:S2095") public InputStream getFileInputStream() { try { return new BufferedInputStream(new FileInputStream(file)); } catch (final FileNotFoundException e) { throw Throwables.propagate(e); } } ArtifactFilesystem(final File file, final String artifactId, final DbArtifactHash hashes, final Long size,
            final String contentType); @Override // suppress warning, this InputStream needs to be closed by the caller, this // cannot be closed in this method @SuppressWarnings("squid:S2095") InputStream getFileInputStream();  }
@Test @Description("Verifies that an exception is thrown on opening an InputStream when file does not exists") public void getInputStreamOfNonExistingFileThrowsException() { final File file = new File("fileWhichTotalDoesNotExists"); final ArtifactFilesystem underTest = new ArtifactFilesystem(file, "fileWhichTotalDoesNotExists", new DbArtifactHash("1", "2", "3"), 0L, null); try { underTest.getFileInputStream(); Assertions.fail("Expected a FileNotFoundException because file does not exists"); } catch (final RuntimeException e) { assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class); } }
@Test @Description("Verifies that an InputStream can be opened if file exists") public void getInputStreamOfExistingFile() throws IOException { final File createTempFile = File.createTempFile(ArtifactFilesystemTest.class.getSimpleName(), ""); createTempFile.deleteOnExit(); final ArtifactFilesystem underTest = new ArtifactFilesystem(createTempFile, ArtifactFilesystemTest.class.getSimpleName(), new DbArtifactHash("1", "2", "3"), 0L, null); final byte[] buffer = new byte[1024]; IOUtils.read(underTest.getFileInputStream(), buffer); }