OSDN Git Service

Update test to improve coverage
authorHiroshi Miura <miurahr@linux.com>
Fri, 15 Apr 2016 13:43:14 +0000 (22:43 +0900)
committerHiroshi Miura <miurahr@linux.com>
Fri, 15 Apr 2016 13:47:21 +0000 (22:47 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
CHANGELOG.md
dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java
dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java

index bbac16b..e3f7b74 100644 (file)
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
 ### Add
 - Add test option for DictZip CLI.
 - Add DictZipInputStream consructor that get a filename as argument.
+- More tests.
 
 ### Changed
 - README: there is no test dependency for commons-io.
index d3ec639..549d28b 100644 (file)
@@ -20,6 +20,14 @@ public class DictZipFileUtilsTest {
     }
 
     @Test
+    public void testIsFileBinaryEquals_sameCanonicalPath() throws Exception {
+        System.out.println("isFileBinaryEquals with same canonical path");
+        File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
+        File secondFile = new File(this.getClass().getResource("/test_util.txt").getFile());
+        assertTrue(DictZipFileUtils.isFileBinaryEquals(firstFile, secondFile));
+    }
+
+    @Test
     public void testIsFileBinaryEquals_false() throws Exception {
         System.out.println("isFileBinaryEquals_false");
         File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
index 112a2b7..33a9e62 100644 (file)
@@ -23,9 +23,7 @@ package org.dict.zip;
 import static org.testng.Assert.*;
 
 import org.testng.SkipException;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
+import org.testng.annotations.*;
 
 import java.io.EOFException;
 import java.io.IOException;
@@ -39,34 +37,56 @@ import java.util.Arrays;
 public class DictZipInputStreamTest {
 
     private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
-    private RandomAccessInputStream in;
     private DictZipInputStream din;
-    private DictZipHeader header;
+
+    @BeforeMethod
+    public void rewind() throws Exception {
+        if (din != null) {
+            din.seek(0);
+        }
+    }
+
+    /**
+     * Test constructor.
+     * @throws Exception
+     */
+    @Test (groups = "init", dependsOnMethods = { "testConstructor_fromFilename",
+            "testConstructor_defaultBufSize"})
+    public void testConstructor() throws Exception {
+        din = new DictZipInputStream(new RandomAccessInputStream(dataFile, "r"), 65534);
+    }
 
     /**
-     * Open output stream.
+     * Test constructor.
      * @throws Exception
      */
-    @BeforeTest
-    public void setUp() throws Exception {
-        in = new RandomAccessInputStream(dataFile, "r");
-        din = new DictZipInputStream(in);
+    @Test (groups = "init")
+    public void testConstructor_defaultBufSize() throws Exception {
+        din = new DictZipInputStream(new RandomAccessInputStream(dataFile, "r"));
     }
 
     /**
-     * Close output stream.
-     * @throws Exception if I/O error occured.
+     * Test constructor from filename.
+     * @throws Exception
      */
-    @AfterTest
-    public void tearDown() throws Exception {
+    @Test (groups = "init")
+    public void testConstructor_fromFilename() throws Exception {
+        din = new DictZipInputStream(dataFile);
+    }
+
+    /**
+     * Test close of stream.
+     * @throws Exception if I/O error occurred.
+     */
+    @Test (dependsOnGroups = { "test" })
+    public void testClose() throws Exception {
         din.close();
-        in.close();
     }
 
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead() throws Exception {
         System.out.println("read");
         int len = 10;
@@ -79,7 +99,7 @@ public class DictZipInputStreamTest {
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead_with_seek() throws Exception {
         System.out.println("read with seek");
         int start = 0x20;
@@ -96,7 +116,7 @@ public class DictZipInputStreamTest {
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead_null() throws Exception {
         System.out.println("read null buffer");
         int len = 10;
@@ -115,7 +135,7 @@ public class DictZipInputStreamTest {
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead_outOfBound() throws Exception {
         System.out.println("read out of buffer size");
         int len = 10;
@@ -134,7 +154,7 @@ public class DictZipInputStreamTest {
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead_zeroSize() throws Exception {
         System.out.println("read zero size");
         int len = 512;
@@ -147,7 +167,7 @@ public class DictZipInputStreamTest {
     /**
      * Test of read method, of class DictZipInputStream.
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testRead_with_seekLast() throws Exception {
         System.out.println("read with seek to last");
         int start = 383273;
@@ -163,12 +183,12 @@ public class DictZipInputStreamTest {
      * Test of readFully method, of class DictZipInputStream.
      * @throws java.lang.Exception
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testReadFully_byteArr() throws Exception {
         System.out.println("readFully");
-        int start = 1;
+        int start = 100;
         int len = 10;
-        in.seek(start);
+        din.seek(start);
         byte[] buf = new byte[len];
         din.readFully(buf);
     }
@@ -177,12 +197,12 @@ public class DictZipInputStreamTest {
      * Test of readFully method, of class DictZipInputStream.
      * @throws java.lang.Exception
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testReadFully_3args() throws Exception {
         System.out.println("readFully");
-        int start = 1;
+        int start = 200;
         int len = 10;
-        in.seek(start);
+        din.seek(start);
         byte[] buf = new byte[len];
         din.readFully(buf, 0, len);
     }
@@ -191,25 +211,66 @@ public class DictZipInputStreamTest {
      * Test of readFully method, of class DictZipInputStream.
      * @throws java.lang.Exception
      */
-    @Test
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
     public void testReadFully_readTrailer() throws IOException {
         System.out.println("readFully and readTrailer");
         byte[] buf = new byte[512];
         try {
             din.readFully(buf);
-        } catch (RuntimeException e) {
-            throw e;
         } catch (EOFException e) {
-            // continue
+            // Normal, continue
         }
         // read trailer
-        try {
-            din.readTrailer();
-        } catch (RuntimeException e) {
-            throw e;
-        }
+        din.readTrailer();
         assertEquals(din.getCrc(), 0x024d1f37);
         assertEquals(din.getLength(), 383783);
     }
 
+    /**
+     * Test getComplength method.
+     * @throws IOException
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testGetCompLength() throws IOException {
+        System.out.println("getCompLength");
+        assertEquals(din.getCompLength(), 136856);
+    }
+
+    /**
+     * Test getMtime method.
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testGetMtime() throws IOException {
+        System.out.println("getMtime");
+        assertEquals(din.getMtime(), 1193780332);
+    }
+
+    /**
+     * Test getChunkLength method.
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testGetChunkLength() throws IOException {
+        System.out.println("getChunkLength");
+        assertEquals(din.getChunkLength(), 58315);
+    }
+
+    /**
+     * Test getChunkCount method.
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testGetChunkCount() throws IOException {
+        System.out.println("getChunkCount");
+        assertEquals(din.getChunkCount(), 7);
+    }
+
+    /**
+     * Test getFilename method.
+     */
+    @Test (groups = "test", dependsOnMethods = { "testConstructor" })
+    public void testGetFilename() throws IOException {
+        System.out.println("getFilename");
+        assertEquals(din.getFilename(), "results.dict");
+    }
+
+
 }