OSDN Git Service

Adjust for checkstyle warnings
authorHiroshi Miura <miurahr@linux.com>
Tue, 18 Jan 2022 14:38:10 +0000 (23:38 +0900)
committerHiroshi Miura <miurahr@linux.com>
Tue, 18 Jan 2022 14:38:10 +0000 (23:38 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
dictzip-lib/src/test/java/org/dict/zip/DictZipFileTest.java
dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java
dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java
dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java
dictzip-lib/src/test/java/org/dict/zip/DictZipOutputStreamTest.java
northside-io/src/main/java/tokyo/northside/io/FileUtils2.java

index 73a9384..957f663 100644 (file)
@@ -57,6 +57,9 @@ import java.util.zip.Deflater;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+/**
+ * Test archive creation and extraction.
+ */
 public class DictZipFileTest {
 
     private static final int BUF_LEN = 58315;
@@ -70,7 +73,7 @@ public class DictZipFileTest {
                 int number = random.nextInt(94);
                 writer.print((char) (32 + number));
             }
-        };
+        }
     }
 
     void prepareLargeTextData(final Path outTextPath, final int size) throws IOException {
@@ -97,9 +100,12 @@ public class DictZipFileTest {
 
     /**
      * Test case to create large archive.
+     * @param tempDir JUnit5 temporary directory..
+     * @throws IOException when file wreite filed.
+     * @throws InterruptedException when external dictzip not executed well.
      */
     @Test
-    public void testFileCreation(@TempDir Path tempDir) throws IOException, InterruptedException {
+    public void testFileCreation(@TempDir final Path tempDir) throws IOException, InterruptedException {
         // Run test when running on Linux and dictzip command installed
         Assumptions.assumeTrue(Paths.get("/usr/bin/dictzip").toFile().exists());
         int size = (BUF_LEN * 512 + 100) / 100000 * 100000;
@@ -156,18 +162,18 @@ public class DictZipFileTest {
 
     /**
      * Test case to extract large archive file.
-     * @param tempDir JUnit5.jupiter TempDir.
+     * @param tempDir JUnit5 temporary directory.
      * @throws IOException when i/o error occurred.
      * @throws InterruptedException when external dictzip not executed well.
      */
     @Test
-    public void testFileReadAceess(@TempDir Path tempDir) throws IOException, InterruptedException {
+    public void testFileReadAceess(@TempDir final Path tempDir) throws IOException, InterruptedException {
         // Run test when running on Linux and dictzip command installed
         Assumptions.assumeTrue(Paths.get("/usr/bin/dictzip").toFile().exists());
         int size = (BUF_LEN * 512 + 100) / 100000 * 100000;
         // --- preparation of data
         int len;
-        int num_chunk = size / BUF_LEN + 1;
+        int numChunk = size / BUF_LEN + 1;
         byte[] buf = new byte[BUF_LEN];
         int[] positions = new int[] {
                 BUF_LEN - 10,
@@ -175,8 +181,8 @@ public class DictZipFileTest {
                 BUF_LEN * 2 + 10,
                 BUF_LEN * 256 - 10,
                 BUF_LEN * 256 + 10,
-                BUF_LEN * (num_chunk /2 - 1) - 10,
-                BUF_LEN * (num_chunk /2 + 1) + 10,
+                BUF_LEN * (numChunk / 2 - 1) - 10,
+                BUF_LEN * (numChunk / 2 + 1) + 10,
                 size - BUF_LEN + 5
         };
         int cases = positions.length;
@@ -222,21 +228,24 @@ public class DictZipFileTest {
      *     When seek to almost end of large dictionary, it cause error
      *     Caused by: java.util.zip.ZipException: invalid distance too far back
      * </p>
+     * @param tempDir JUnit5 temporary directory.
+     * @throws IOException when i/o error occurred.
+     * @throws InterruptedException when external dictzip not executed well.
      */
     @Test
-    public void testFileInputOutput(@TempDir Path tempDir) throws IOException, InterruptedException {
+    public void testFileInputOutput(@TempDir final Path tempDir) throws IOException, InterruptedException {
         // Run test when running on Linux and dictzip command installed
         Assumptions.assumeTrue(Paths.get("/usr/bin/dictzip").toFile().exists());
         int size = (BUF_LEN * 512 + 100) / 100000 * 100000;
         // int size = 45000000;  // about 45MB
-        int num_chunk = size / BUF_LEN + 1;
+        int numChunk = size / BUF_LEN + 1;
         byte[] buf = new byte[BUF_LEN];
         int[] positions = new int[] {
                 BUF_LEN - 10,
                 BUF_LEN + 10,
                 BUF_LEN * 2 + 10,
-                BUF_LEN * (num_chunk /2 - 1) - 10,
-                BUF_LEN * (num_chunk /2 + 1) + 10,
+                BUF_LEN * (numChunk / 2 - 1) - 10,
+                BUF_LEN * (numChunk / 2 + 1) + 10,
                 size - BUF_LEN + 5
         };
         int cases = positions.length;
index 95d68cc..7d65c07 100644 (file)
@@ -7,6 +7,10 @@ import java.io.IOException;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+/**
+ * Test of DictZipFileUtils.
+ * @author Hiroshi Miura
+ */
 public class DictZipFileUtilsTest {
 
     /**
index 18df67e..b0776f7 100644 (file)
@@ -44,10 +44,10 @@ import java.nio.file.Path;
 import org.dict.zip.DictZipHeader.CompressionLevel;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
+import tokyo.northside.io.FileUtils2;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static tokyo.northside.io.FileUtils2.contentEquals;
 
 
 /**
@@ -113,10 +113,11 @@ public class DictZipHeaderTest {
    /**
      * Test of readHeader method, of class DictZipHeader.
      *
-     * @throws java.lang.Exception if file I/O error occurred.
+    * @param tempDir JUnit5 temporary directory.
+    * @throws java.lang.Exception if file I/O error occurred.
      */
     @Test
-    public void testReadHeaderNonGZip(@TempDir Path tempDir) throws Exception {
+    public void testReadHeaderNonGZip(@TempDir final Path tempDir) throws Exception {
         byte[] b = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         File testFile = tempDir.resolve("DictZipOutCon.txt.dz").toFile();
         FileOutputStream outFile = new FileOutputStream(testFile);
@@ -135,10 +136,11 @@ public class DictZipHeaderTest {
     /**
      * Test of readHeader method, of class DictZipHeader.
      *
+     * @param tempDir JUnit5 temporary directory.
      * @throws java.lang.Exception if file I/O error occurred.
      */
     @Test
-    public void testReadHeaderGZipMagic(@TempDir Path tempDir) throws Exception {
+    public void testReadHeaderGZipMagic(@TempDir final Path tempDir) throws Exception {
         byte[] b = {(byte) 0x1f, (byte) 0x8b, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         File testFile = tempDir.resolve("DictZipOutCon.txt.dz").toFile();
         FileOutputStream outFile = new FileOutputStream(testFile);
@@ -222,10 +224,11 @@ public class DictZipHeaderTest {
     /**
      * Test of writeHeader method.
      *
+     * @param tempDir JUnit5 temporary directory.
      * @throws Exception if file I/O error occurred.
      */
     @Test
-    public void testWriteHeader(@TempDir Path tempDir) throws Exception {
+    public void testWriteHeader(@TempDir final Path tempDir) throws Exception {
         File testFile = tempDir.resolve("DictZipHeader.dz").toFile();
         FileOutputStream outFile = new FileOutputStream(testFile);
         DictZipHeader header = new DictZipHeader(1024, 256);
@@ -242,7 +245,7 @@ public class DictZipHeaderTest {
         DictZipHeader.writeHeader(header, outFile);
         outFile.close();
         String expectedHeader = this.getClass().getResource("/test.header.dz").getFile();
-        assertTrue(contentEquals(testFile, new File(expectedHeader), 8, 45));
+        assertTrue(FileUtils2.contentEquals(testFile, new File(expectedHeader), 8, 45));
         testFile.deleteOnExit();
     }
 }
index fefb803..4b4d147 100644 (file)
@@ -39,6 +39,7 @@ package org.dict.zip;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import tokyo.northside.io.IOUtils2;
 
 import java.io.EOFException;
 import java.io.FileInputStream;
@@ -46,8 +47,8 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static tokyo.northside.io.IOUtils2.contentEquals;
 
 /**
  * Test of DictZipInputStream.
@@ -64,7 +65,7 @@ public class DictZipInputStreamTest {
     @Test
     public void testConstructorDefaultBufSize() throws Exception {
         try (DictZipInputStream din = new DictZipInputStream(new RandomAccessInputStream(dataFile, "r"))) {
-            // pass
+            assertNotNull(din);
         }
     }
 
@@ -75,7 +76,7 @@ public class DictZipInputStreamTest {
     @Test
     public void testConstructorFromFilename() throws Exception {
         try (DictZipInputStream din = new DictZipInputStream(dataFile)) {
-            // pass
+            assertNotNull(din);
         }
     }
 
@@ -360,7 +361,7 @@ public class DictZipInputStreamTest {
             }
             FileInputStream in2 = new FileInputStream(this.getClass().getResource("/test.dict.expected").getFile());
             in2.skip(start);
-            assertTrue(contentEquals(din, in2, 0, len));
+            assertTrue(IOUtils2.contentEquals(din, in2, 0, len));
         }
     }
 }
index e333dca..63b9e0d 100644 (file)
@@ -60,9 +60,10 @@ public class DictZipOutputStreamTest {
 
     /**
      * Test of close method, of class DictZipOutputStream.
+     * @param tempDir JUnit5 temporary directory.
      */
     @Test
-    public void testClose(@TempDir Path tempDir) {
+    public void testClose(@TempDir final Path tempDir) {
         byte[] byteArray = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         try {
             File testOutFile = tempDir.resolve("DictZipOutCon.txt").toFile();
@@ -84,10 +85,11 @@ public class DictZipOutputStreamTest {
 
     /**
      * Test of write method, of class DictZipOutputStream.
+     * @param tempDir JUnit5 temporary directory.
      * @throws Exception when i/o error.
      */
     @Test
-    public void testWrite3args(@TempDir Path tempDir) throws Exception {
+    public void testWrite3args(@TempDir final Path tempDir) throws Exception {
         byte[] b = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         File testOutFile = tempDir.resolve("DictZipOutCon.txt").toFile();
         RandomAccessOutputStream outFile = new RandomAccessOutputStream(
@@ -106,9 +108,10 @@ public class DictZipOutputStreamTest {
 
     /**
      * Test of write method, of class DictZipOutputStream.
+     * @param tempDir JUnit5 temporary directory.
      */
     @Test
-    public void testWriteInt(@TempDir Path tempDir) {
+    public void testWriteInt(@TempDir final Path tempDir) {
         int b = 100;
         TestDictZipOutputStream instance;
         try {
@@ -124,9 +127,10 @@ public class DictZipOutputStreamTest {
 
     /**
      * Test of finish method, of class DictZipOutputStream.
+     * @param tempDir JUnit5 temporary directory.
      */
     @Test
-    public void testFinish(@TempDir Path tempDir) {
+    public void testFinish(@TempDir final Path tempDir) {
         byte[] byteArray = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
         TestDictZipOutputStream instance = null;
         try {
index 1705848..27adebe 100644 (file)
@@ -44,6 +44,8 @@ import org.jetbrains.annotations.NotNull;
  */
 public final class FileUtils2 {
 
+    private FileUtils2() { }
+
     /**
      * Compare file contents in range. Both files must be files (not directories) and exist.
      *