This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 539cc1a1a8399e7355b0877c3253261c3c889de0 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Nov 12 09:49:15 2023 -0500 Use final - Sort members - Format nits --- .../lz4/FramedLZ4CompressorOutputStreamTest.java | 47 ++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java index 97fee10a6..4ead6657f 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStreamTest.java @@ -25,42 +25,39 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class FramedLZ4CompressorOutputStreamTest { - + + @Test + public void testFinishWithNoWrite() throws IOException { + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer, + new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { + // do nothing here. this will test that flush on close doesn't throw any exceptions if no data is written. + } + assertTrue(buffer.size() == 15, "only the trailer gets written."); + } + @Test public void testWriteByteArrayVsWriteByte() throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("abcdefghijklmnop"); - byte[] random = sb.toString().getBytes(); - try (FramedLZ4CompressorOutputStream compressor = - new FramedLZ4CompressorOutputStream(buffer, - new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { + final byte[] random = sb.toString().getBytes(); + try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer, + new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { compressor.write(random); compressor.finish(); } - byte[] bulkOutput = buffer.toByteArray(); + final byte[] bulkOutput = buffer.toByteArray(); buffer = new ByteArrayOutputStream(); - try (FramedLZ4CompressorOutputStream compressor = - new FramedLZ4CompressorOutputStream(buffer, - new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { - for (int i = 0; i < random.length; i++) { - compressor.write(random[i]); + try (FramedLZ4CompressorOutputStream compressor = new FramedLZ4CompressorOutputStream(buffer, + new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { + for (final byte element : random) { + compressor.write(element); } compressor.finish(); } - byte[] singleOutput = buffer.toByteArray(); + final byte[] singleOutput = buffer.toByteArray(); assertTrue(Arrays.equals(bulkOutput, singleOutput)); } - - @Test - public void testFinishWithNoWrite() throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - try (FramedLZ4CompressorOutputStream compressor = - new FramedLZ4CompressorOutputStream(buffer, - new FramedLZ4CompressorOutputStream.Parameters(FramedLZ4CompressorOutputStream.BlockSize.K64, true, false, false))) { - // do nothing here. this will test that flush on close doesn't throw any exceptions if no data is written. - } - assertTrue(buffer.size() == 15, "only the trailer gets written."); - } - + }