Skip to content

Commit

Permalink
Reduce boilerplate in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 12, 2024
1 parent c797ca7 commit b743130
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,10 @@ private ZipFile newZipFile(final File file) throws IOException {
}

private void readStream(final InputStream in, final ArchiveEntry entry, final Map<String, List<List<Long>>> map) throws IOException {
final byte[] buf = new byte[4096];
final InputStreamStatistics stats = (InputStreamStatistics) in;
while (in.read(buf) != -1) {
// consume all.
}

IOUtils.consume(in);
final String name = entry.getName();
final List<List<Long>> list = map.computeIfAbsent(name, k -> new ArrayList<>());

final long t = stats.getUncompressedCount();
final long b = stats.getCompressedCount();
list.add(Arrays.asList(t, b));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public void testBrotliDecode() throws IOException {
BrotliCompressorInputStream brotliInputStream = new BrotliCompressorInputStream(inputStream)) {
final byte[] expected = readAllBytes("brotli.testdata.uncompressed");
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
int readByte = -1;
while ((readByte = brotliInputStream.read()) != -1) {
bos.write(readByte);
}
IOUtils.copy(brotliInputStream, bos);
assertArrayEquals(expected, bos.toByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ public void testZstdDecode() throws IOException {
ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream)) {
final byte[] expected = readAllBytes("zstandard.testdata");
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
int readByte = -1;
while ((readByte = zstdInputStream.read()) != -1) {
bos.write(readByte);
}
IOUtils.copy(zstdInputStream, bos);
assertArrayEquals(expected, bos.toByteArray());
}
}
Expand All @@ -157,10 +154,7 @@ public void testZstdDecodeWithNoPool() throws IOException {
ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, NoPool.INSTANCE)) {
final byte[] expected = readAllBytes("zstandard.testdata");
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
int readByte = -1;
while ((readByte = zstdInputStream.read()) != -1) {
bos.write(readByte);
}
IOUtils.copy(zstdInputStream, bos);
assertArrayEquals(expected, bos.toByteArray());
}
}
Expand All @@ -172,10 +166,7 @@ public void testZstdDecodeWithRecyclingBufferPool() throws IOException {
ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, RecyclingBufferPool.INSTANCE)) {
final byte[] expected = readAllBytes("zstandard.testdata");
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
int readByte = -1;
while ((readByte = zstdInputStream.read()) != -1) {
bos.write(readByte);
}
IOUtils.copy(zstdInputStream, bos);
assertArrayEquals(expected, bos.toByteArray());
}
}
Expand Down

0 comments on commit b743130

Please sign in to comment.