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 e2a35472152eaee5fd2c12fa06a3bc18055a7caa
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Nov 26 10:24:40 2024 -0500

    Refactor test
    
    - Use final
    - Fix Chekstyle
---
 .../archivers/zip/ZipEightByteInteger.java         |  4 +-
 .../archivers/zip/ZipEightByteIntegerTest.java     | 57 ++++++++++++----------
 2 files changed, 33 insertions(+), 28 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
index 567ef49d2..2d1cd6545 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
@@ -33,7 +33,7 @@ public final class ZipEightByteInteger implements 
Serializable {
     private static final long serialVersionUID = 1L;
 
     /**
-     * Constant for a value of zero. 
+     * Constant for a value of zero.
      */
     public static final ZipEightByteInteger ZERO = new ZipEightByteInteger(0);
 
@@ -56,7 +56,7 @@ public final class ZipEightByteInteger implements 
Serializable {
      * @return value as eight bytes in big-endian byte order
      */
     public static byte[] getBytes(final long value) {
-        ByteBuffer buffer = 
ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
+        final ByteBuffer buffer = 
ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
         buffer.putLong(value);
         return buffer.array();
     }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
index a80cb753a..41d531660 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
@@ -25,12 +25,26 @@ import java.math.BigInteger;
 import org.junit.jupiter.api.Test;
 
 /**
- * JUnit tests for 
org.apache.commons.compress.archivers.zip.ZipEightByteInteger.
+ * Tests {@link ZipEightByteInteger}.
  */
 public class ZipEightByteIntegerTest {
 
+    private byte[] getBytes(final ZipEightByteInteger zl) {
+        final byte[] result = zl.getBytes();
+        assertEquals(8, result.length, "length getBytes");
+        return result;
+    }
+
+    private byte[] newMaxByteArrayValue() {
+        return new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 
0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+    }
+
+    private ZipEightByteInteger newMaxValue() {
+        return new ZipEightByteInteger(newMaxByteArrayValue());
+    }
+
     /**
-     * Test conversion from bytes.
+     * Tests conversion from bytes.
      */
     @Test
     public void testBIFromBytes() {
@@ -40,35 +54,31 @@ public class ZipEightByteIntegerTest {
     }
 
     /**
-     * Test conversion from max value.
+     * Tests conversion from max value.
      */
     @Test
     public void testBIFromMaxValue() {
         // https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
         // 4.4.1.1 All fields unless otherwise noted are unsigned and stored 
in Intel low-byte:high-byte, low-word:high-word order.
-        final ZipEightByteInteger zipEightByteInteger = new 
ZipEightByteInteger(
-                new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 
0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
+        final ZipEightByteInteger zipEightByteInteger = newMaxValue();
         assertEquals("18446744073709551615", 
zipEightByteInteger.getValue().toString());
     }
 
     /**
-     * Test conversion from bytes.
+     * Tests conversion from bytes.
      */
     @Test
     public void testBILongFromBytes() {
-        final byte[] val = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 
0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-        final ZipEightByteInteger zl = new ZipEightByteInteger(val);
+        final ZipEightByteInteger zl = newMaxValue();
         assertEquals(0XFFFFFFFFFFFFFFFFL, zl.getLongValue(), "longValue from 
bytes");
     }
 
     /**
-     * Test conversion to bytes.
+     * Tests conversion to bytes.
      */
     @Test
     public void testBIToBytes() {
-        final ZipEightByteInteger zl = new 
ZipEightByteInteger(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1));
-        final byte[] result = zl.getBytes();
-        assertEquals(8, result.length, "length getBytes");
+        final byte[] result = getBytes(new 
ZipEightByteInteger(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1)));
         assertEquals((byte) 0xFE, result[0], "first byte getBytes");
         assertEquals((byte) 0xFF, result[1], "second byte getBytes");
         assertEquals((byte) 0xFF, result[2], "third byte getBytes");
@@ -80,7 +90,7 @@ public class ZipEightByteIntegerTest {
     }
 
     /**
-     * Test the contract of the equals method.
+     * Tests the contract of the equals method.
      */
     @Test
     public void testEquals() {
@@ -100,7 +110,7 @@ public class ZipEightByteIntegerTest {
     }
 
     /**
-     * Test conversion from bytes.
+     * Tests conversion from bytes.
      */
     @Test
     public void testLongFromBytes() {
@@ -110,12 +120,11 @@ public class ZipEightByteIntegerTest {
     }
 
     /**
-     * Test conversion to bytes.
+     * Tests conversion to bytes.
      */
     @Test
     public void testLongToBytes() {
-        final ZipEightByteInteger zl = new ZipEightByteInteger(0xAB12345678L);
-        final byte[] result = zl.getBytes();
+        final byte[] result = getBytes(new ZipEightByteInteger(0xAB12345678L));
         assertEquals(8, result.length, "length getBytes");
         assertEquals(0x78, result[0], "first byte getBytes");
         assertEquals(0x56, result[1], "second byte getBytes");
@@ -128,27 +137,23 @@ public class ZipEightByteIntegerTest {
     }
 
     /**
-     * Test sign handling.
+     * Tests sign handling.
      */
     @Test
     public void testSign() {
-        final ZipEightByteInteger zl = new ZipEightByteInteger(
-                new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 
0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
-        
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1).setBit(0), 
zl.getValue());
+        
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1).setBit(0), 
newMaxValue().getValue());
     }
 
     /**
-     * Test {@link ZipEightByteInteger#toString()}.
+     * Tests {@link ZipEightByteInteger#toString()}.
      */
     @Test
     public void testToString() {
-        final ZipEightByteInteger zipEightByteInteger = new 
ZipEightByteInteger(
-                new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 
0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
-        assertEquals("ZipEightByteInteger value: 18446744073709551615", 
zipEightByteInteger.toString());
+        assertEquals("ZipEightByteInteger value: 18446744073709551615", 
newMaxValue().toString());
     }
 
     /**
-     * Test {@link ZipEightByteInteger#toUnsignedBigInteger(long)}.
+     * Tests {@link ZipEightByteInteger#toUnsignedBigInteger(long)}.
      */
     @Test
     public void testToUnsignedBigInteger() {

Reply via email to