From: Hiroshi Miura Date: Sat, 9 Apr 2016 12:32:16 +0000 (+0900) Subject: Upgrade test coverage X-Git-Tag: v0.6.0~6 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4f91abaeae3dd3a5556f73d13709725ebc02d545;p=dictzip-java%2Fdictzip-java.git Upgrade test coverage Signed-off-by: Hiroshi Miura --- diff --git a/dictzip-cli/src/main/java/org/dict/zip/cli/CommandLine.java b/dictzip-cli/src/main/java/org/dict/zip/cli/CommandLine.java index ba53ca7..8968091 100644 --- a/dictzip-cli/src/main/java/org/dict/zip/cli/CommandLine.java +++ b/dictzip-cli/src/main/java/org/dict/zip/cli/CommandLine.java @@ -42,7 +42,7 @@ public class CommandLine { /** * Target files for zip or unzip. */ - protected final List targetFiles = new ArrayList(); + protected final List targetFiles = new ArrayList<>(); private static String getString(final String key) { return AppConsts.RESOURCE_BUNDLE.getString(key); diff --git a/dictzip-cli/src/test/java/org/dict/zip/cli/CommandLineTest.java b/dictzip-cli/src/test/java/org/dict/zip/cli/CommandLineTest.java new file mode 100644 index 0000000..4826464 --- /dev/null +++ b/dictzip-cli/src/test/java/org/dict/zip/cli/CommandLineTest.java @@ -0,0 +1,206 @@ +package org.dict.zip.cli; + +import org.dict.zip.DictZipHeader; +import org.testng.annotations.Test; + +import java.util.ArrayList; + +import static org.testng.Assert.*; + +/** + * Created by miurahr on 16/04/09. + */ +public class CommandLineTest { + @Test + public void testParse_help() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-h"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_helpLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--help"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_version() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-v"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_versionLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--version"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_license() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-L"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_licenseLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--license"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + } + + @Test + public void testParse_keep() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-k"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isKeep()); + } + + @Test + public void testParse_keepLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--keep"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isKeep()); + } + + @Test + public void testParse_stdout() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-c"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isStdout()); + } + + @Test + public void testParse_stdoutLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--stdout"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isStdout()); + } + + @Test + public void testParse_force() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-f"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isForce()); + } + + @Test + public void testParse_forceLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--force"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isForce()); + } + + @Test + public void testParse_decompress() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-d"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isDecompress()); + } + + @Test + public void testParse_decompressLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--decompress"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isDecompress()); + } + + @Test + public void testParse_list() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-l"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isList()); + } + + @Test + public void testParse_listLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--list"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.options.isList()); + } + + @Test + public void testParse_levelFast() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-1"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertEquals(commandLine.options.getLevel(), DictZipHeader.CompressionLevel.BEST_SPEED); + } + + @Test + public void testParse_levelFastLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--fast"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertEquals(commandLine.options.getLevel(), DictZipHeader.CompressionLevel.BEST_SPEED); + } + + @Test + public void testParse_levelBest() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-9"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertEquals(commandLine.options.getLevel(), DictZipHeader.CompressionLevel.BEST_COMPRESSION); + } + + @Test + public void testParse_levelBestLong() throws Exception { + final String[] argv = new String[1]; + argv[0] = "--best"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertEquals(commandLine.options.getLevel(), DictZipHeader.CompressionLevel.BEST_COMPRESSION); + } + + @Test + public void testParse_levelDefault() throws Exception { + final String[] argv = new String[1]; + argv[0] = "-6"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertEquals(commandLine.options.getLevel(), DictZipHeader.CompressionLevel.DEFAULT_COMPRESSION); + } + + @Test + public void testParse_target() throws Exception { + final String[] argv = new String[1]; + argv[0] = "target_filename"; + CommandLine commandLine = new CommandLine(); + commandLine.parse(argv); + assertTrue(commandLine.getTargetFiles().equals(new ArrayList (){{add("target_filename");}})); + } + +} \ No newline at end of file diff --git a/dictzip-cli/src/test/java/org/dict/zip/cli/DictDataTest.java b/dictzip-cli/src/test/java/org/dict/zip/cli/DictDataTest.java index b87292d..183ff43 100644 --- a/dictzip-cli/src/test/java/org/dict/zip/cli/DictDataTest.java +++ b/dictzip-cli/src/test/java/org/dict/zip/cli/DictDataTest.java @@ -26,6 +26,7 @@ import java.io.File; import java.net.URL; import org.dict.zip.DictZipHeader; +import org.dict.zip.DictZipFileUtils; import org.testng.annotations.Test; @@ -61,7 +62,7 @@ public class DictDataTest { instance.doZip(DictZipHeader.CompressionLevel.DEFAULT_COMPRESSION); File resultFile = new File(testFile + ".dz"); File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected").getFile()); - assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); + assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); resultFile.deleteOnExit(); } @@ -79,7 +80,7 @@ public class DictDataTest { File resultFile = new File(zippedFile); File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.best") .getFile()); - assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); + assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); resultFile.deleteOnExit(); } @@ -97,7 +98,7 @@ public class DictDataTest { File resultFile = new File(zippedFile); File expectFile = new File(this.getClass().getResource("/test_dozip.dict.dz.expected.fast") .getFile()); - assertTrue(StaticUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); + assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, expectFile, 10, 512)); resultFile.deleteOnExit(); } @@ -118,7 +119,7 @@ public class DictDataTest { URL resultUrl = this.getClass().getResource("/test.dict"); File resultFile = new File(resultUrl.getFile()); URL expectedUrl = this.getClass().getResource("/test.dict.expected"); - assertTrue(StaticUtils.isFileBinaryEquals(resultFile, new File(expectedUrl.getFile()))); + assertTrue(DictZipFileUtils.isFileBinaryEquals(resultFile, new File(expectedUrl.getFile()))); resultFile.deleteOnExit(); } } diff --git a/dictzip-lib/src/main/java/org/dict/zip/DictZipFileUtils.java b/dictzip-lib/src/main/java/org/dict/zip/DictZipFileUtils.java index 06292eb..1b2c4a2 100644 --- a/dictzip-lib/src/main/java/org/dict/zip/DictZipFileUtils.java +++ b/dictzip-lib/src/main/java/org/dict/zip/DictZipFileUtils.java @@ -1,16 +1,74 @@ package org.dict.zip; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; import java.util.Arrays; /** * Created by Hiroshi Miura on 16/04/09. */ -class DictZipFileUtils { - private DictZipFileUtils() {} +public class DictZipFileUtils { + /** + * Reads unsigned byte. + * + * @param in input stream to read. + * @return unsigned byte value. + * @throws IOException when error in file reading. + */ + public static int readUByte(final InputStream in) throws IOException { + int b = in.read(); + if (b == -1) { + throw new EOFException(); + } + return b; + } + + /** + * Reads unsigned integer in Intel byte order. + * + * @param in input stream to read. + * @return unsigned integer value. + * @throws IOException when error in file reading. + */ + public static long readUInt(final InputStream in) throws IOException { + long s = readUShort(in); + return ((long) readUShort(in) << 16) | s; + } + + /** + * Reads unsigned short in Intel byte order. + * + * @param in input stream to read. + * @return unsigned short value. + * @throws IOException when error in file reading. + */ + public static int readUShort(final InputStream in) throws IOException { + int b = readUByte(in); + return ((int) readUByte(in) << 8) | b; + } + + /** + * Writes integer in Intel byte order. + * + * @param out output stream to write. + * @param i integer to write. + * @throws IOException when error in file output. + */ + public static void writeInt(final OutputStream out, final int i) throws IOException { + writeShort(out, i & 0xffff); + writeShort(out, (i >> 16) & 0xffff); + } + + /** + * Writes short integer in Intel byte order. + * + * @param out output stream to write. + * @param s short integer to write. + * @throws IOException when error in file output. + */ + public static void writeShort(final OutputStream out, final int s) throws IOException { + out.write(s & 0xff); + out.write((s >> 8) & 0xff); + } /** * Compare binary files. Both files must be files (not directories) and exist. @@ -20,7 +78,7 @@ class DictZipFileUtils { * @return boolean - true if files are binery equal * @throws IOException - error in function */ - static boolean isFileBinaryEquals(File first, File second) throws IOException { + public static boolean isFileBinaryEquals(File first, File second) throws IOException { return isFileBinaryEquals(first, second, 0, first.length()); } @@ -34,7 +92,7 @@ class DictZipFileUtils { * @return boolean - true if files are binery equal * @throws IOException - error in function */ - static boolean isFileBinaryEquals( File first, File second, final long off, final long len) throws IOException { + public static boolean isFileBinaryEquals( File first, File second, final long off, final long len) throws IOException { boolean result= false; final int BUFFER_SIZE = 65536; final int COMP_SIZE = 512; @@ -113,4 +171,7 @@ class DictZipFileUtils { return result; } + + private DictZipFileUtils() { + } } diff --git a/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java b/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java index 1bb001f..beaae29 100644 --- a/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java +++ b/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java @@ -21,7 +21,6 @@ package org.dict.zip; -import java.io.EOFException; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -192,23 +191,23 @@ public class DictZipHeader { crc.reset(); // Check header magic - if (readUShort(in) != GZIP_MAGIC) { + if (DictZipFileUtils.readUShort(in) != GZIP_MAGIC) { throw new IOException("Not in GZIP format"); } // Check compression method - if (readUByte(in) != Deflater.DEFLATED) { + if (DictZipFileUtils.readUByte(in) != Deflater.DEFLATED) { throw new IOException("Unsupported compression method"); } // Read flags - int flg = readUByte(in); + int flg = DictZipFileUtils.readUByte(in); for (int i = 0; i < GZIPFLAG_SIZE; i++) { int testbit = 1 << i; if ((flg & testbit) == testbit) { h.gzipFlag.set(i); } } - h.mtime = readUInt(in); - int compFlg = readUByte(in); + h.mtime = DictZipFileUtils.readUInt(in); + int compFlg = DictZipFileUtils.readUByte(in); if (compFlg == 0x02) { h.extraFlag = CompressionLevel.BEST_COMPRESSION; } else if (compFlg == 0x04) { @@ -218,7 +217,7 @@ public class DictZipHeader { } else { throw new IOException("Corrupt GZIP header"); } - int hos = readUByte(in); + int hos = DictZipFileUtils.readUByte(in); h.headerOS = OperatingSystem.UNKNOWN; for (OperatingSystem os: OperatingSystem.values()) { if (hos == os.value) { @@ -229,24 +228,24 @@ public class DictZipHeader { h.headerLength = DICTZIP_HEADER_LEN; // Optional extra field if (h.gzipFlag.get(FEXTRA)) { - h.extraLength = readUShort(in); + h.extraLength = DictZipFileUtils.readUShort(in); h.headerLength += h.extraLength + 2; - h.subfieldID1 = (byte) readUByte(in); - h.subfieldID2 = (byte) readUByte(in); - h.subfieldLength = readUShort(in); // 2 bytes subfield length - h.subfieldVersion = readUShort(in); // 2 bytes subfield version - h.chunkLength = readUShort(in); // 2 bytes chunk length - h.chunkCount = readUShort(in); // 2 bytes chunk count + h.subfieldID1 = (byte) DictZipFileUtils.readUByte(in); + h.subfieldID2 = (byte) DictZipFileUtils.readUByte(in); + h.subfieldLength = DictZipFileUtils.readUShort(in); // 2 bytes subfield length + h.subfieldVersion = DictZipFileUtils.readUShort(in); // 2 bytes subfield version + h.chunkLength = DictZipFileUtils.readUShort(in); // 2 bytes chunk length + h.chunkCount = DictZipFileUtils.readUShort(in); // 2 bytes chunk count h.chunks = new int[h.chunkCount]; for (int i = 0; i < h.chunkCount; i++) { - h.chunks[i] = readUShort(in); + h.chunks[i] = DictZipFileUtils.readUShort(in); } } // Skip optional file name if (h.gzipFlag.get(FNAME)) { StringBuilder sb = new StringBuilder(); int ubyte; - while ((ubyte = readUByte(in)) != 0) { + while ((ubyte = DictZipFileUtils.readUByte(in)) != 0) { sb.append((char) (ubyte & 0xff)); h.headerLength++; } @@ -255,7 +254,7 @@ public class DictZipHeader { } // Skip optional file comment if (h.gzipFlag.get(FCOMMENT)) { - while (readUByte(in) != 0) { + while (DictZipFileUtils.readUByte(in) != 0) { h.headerLength++; } h.headerLength++; @@ -263,7 +262,7 @@ public class DictZipHeader { // Check optional header CRC if (h.gzipFlag.get(FHCRC)) { int v = (int) crc.getValue() & 0xffff; - if (readUShort(in) != v) { + if (DictZipFileUtils.readUShort(in) != v) { throw new IOException("Corrupt GZIP header"); } h.headerLength += 2; @@ -271,45 +270,6 @@ public class DictZipHeader { h.initOffsets(); } - /** - * Reads unsigned byte. - * - * @param in input stream to read. - * @return unsigned byte value. - * @throws java.io.IOException when error in file reading. - */ - public static int readUByte(final InputStream in) throws IOException { - int b = in.read(); - if (b == -1) { - throw new EOFException(); - } - return b; - } - - /** - * Reads unsigned integer in Intel byte order. - * - * @param in input stream to read. - * @return unsigned integer value. - * @throws java.io.IOException when error in file reading. - */ - public static long readUInt(final InputStream in) throws IOException { - long s = readUShort(in); - return ((long) readUShort(in) << 16) | s; - } - - /** - * Reads unsigned short in Intel byte order. - * - * @param in input stream to read. - * @return unsigned short value. - * @throws java.io.IOException when error in file reading. - */ - public static int readUShort(final InputStream in) throws IOException { - int b = readUByte(in); - return ((int) readUByte(in) << 8) | b; - } - @Override public final String toString() { StringBuilder sb = new StringBuilder(); @@ -352,7 +312,7 @@ public class DictZipHeader { headerCrc.update(bb.array()); } for (int i = 0; i < h.chunkCount; i++) { - writeShort(out, h.chunks[i]); + DictZipFileUtils.writeShort(out, h.chunks[i]); } if (h.gzipFlag.get(FHCRC)) { for (int i = 0; i < h.chunkCount; i++) { @@ -378,35 +338,11 @@ public class DictZipHeader { out.write(0); } if (h.gzipFlag.get(FHCRC)) { - writeShort(out, (int) headerCrc.getValue()); + DictZipFileUtils.writeShort(out, (int) headerCrc.getValue()); } } /** - * Writes integer in Intel byte order. - * - * @param out output stream to write. - * @param i integer to write. - * @throws java.io.IOException when error in file output. - */ - public static void writeInt(final OutputStream out, final int i) throws IOException { - writeShort(out, i & 0xffff); - writeShort(out, (i >> 16) & 0xffff); - } - - /** - * Writes short integer in Intel byte order. - * - * @param out output stream to write. - * @param s short integer to write. - * @throws java.io.IOException when error in file output. - */ - public static void writeShort(final OutputStream out, final int s) throws IOException { - out.write(s & 0xff); - out.write((s >> 8) & 0xff); - } - - /** * Offset getter. * * @param start total offset bytes. diff --git a/dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java b/dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java index d521081..d6c2498 100644 --- a/dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java +++ b/dictzip-lib/src/main/java/org/dict/zip/DictZipInputStream.java @@ -32,6 +32,8 @@ import java.util.zip.CRC32; import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; +import static org.dict.zip.DictZipFileUtils.readUInt; + /** * DictZipInputStream. @@ -277,14 +279,10 @@ public class DictZipInputStream extends InflaterInputStream { RandomAccessInputStream rain = (RandomAccessInputStream) in; compLength = rain.getLength(); rain.seek(compLength - 8); - crcVal = readUInt(rain); - totalLength = readUInt(rain); + crcVal = readUInt(rain); + totalLength = readUInt(rain); } else { throw new IOException("Illegal type of InputStream."); } } - - private long readUInt(final InputStream in) throws IOException { - return DictZipHeader.readUInt(in); - } } diff --git a/dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java b/dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java index ea77043..5878e2a 100644 --- a/dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java +++ b/dictzip-lib/src/test/java/org/dict/zip/DictZipFileUtilsTest.java @@ -2,20 +2,43 @@ package org.dict.zip; import org.testng.annotations.Test; +import java.io.File; + import static org.testng.Assert.*; /** - * Created by miurahr on 16/04/09. + * Created by Hiroshi Miura on 16/04/09. */ public class DictZipFileUtilsTest { @Test public void testIsFileBinaryEquals() throws Exception { - + System.out.println("isFileBinaryEquals"); + File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile()); + File secondFile = new File(this.getClass().getResource("/test_util1.txt").getFile()); + assertTrue(DictZipFileUtils.isFileBinaryEquals(firstFile, secondFile)); } @Test - public void testIsFileBinaryEquals1() throws Exception { + public void testIsFileBinaryEquals_false() throws Exception { + System.out.println("isFileBinaryEquals_false"); + File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile()); + File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile()); + assertFalse(DictZipFileUtils.isFileBinaryEquals(firstFile, secondFile)); + } + @Test + public void testIsFileBinaryEquals_range() throws Exception { + System.out.println("isFileBinaryEquals_range"); + File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile()); + File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile()); + assertTrue(DictZipFileUtils.isFileBinaryEquals(firstFile, secondFile, 10, 64)); } + @Test + public void testIsFileBinaryEquals_range_false() throws Exception { + System.out.println("isFileBinaryEquals_range_false"); + File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile()); + File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile()); + assertFalse(DictZipFileUtils.isFileBinaryEquals(firstFile, secondFile, 0, 64)); + } } \ No newline at end of file diff --git a/dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java b/dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java index 1fd2c80..8663b3e 100644 --- a/dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java +++ b/dictzip-lib/src/test/java/org/dict/zip/DictZipHeaderTest.java @@ -53,7 +53,7 @@ public class DictZipHeaderTest { System.out.println("readHeader"); String dataFile = this.getClass().getResource("/test.dict.dz").getFile(); DictZipHeader result = DictZipHeader.readHeader(dataFile); - assertEquals(toStringExpResult(), result.toString()); + assertEquals(result.toString(), toStringExpResult()); } /** @@ -62,6 +62,45 @@ public class DictZipHeaderTest { * @throws java.lang.Exception if file I/O error occurred. */ @Test + public void testReadHeader_type() throws Exception { + System.out.println("readHeader"); + String dataFile = this.getClass().getResource("/test.dict.dz").getFile(); + DictZipHeader result = DictZipHeader.readHeader(dataFile); + assertEquals(result.getType(), "dzip"); + } + + /** + * Test of readHeader method, of class DictZipHeader. + * + * @throws java.lang.Exception if file I/O error occurred. + */ + @Test + public void testReadHeader_filename() throws Exception { + System.out.println("readHeader"); + String dataFile = this.getClass().getResource("/test.dict.dz").getFile(); + DictZipHeader result = DictZipHeader.readHeader(dataFile); + assertEquals(result.getFilename(), "results.dict"); + } + + /** + * Test of readHeader method, of class DictZipHeader. + * + * @throws java.lang.Exception if file I/O error occurred. + */ + @Test + public void testReadHeader_chunkCount() throws Exception { + System.out.println("readHeader"); + String dataFile = this.getClass().getResource("/test.dict.dz").getFile(); + DictZipHeader result = DictZipHeader.readHeader(dataFile); + assertEquals(result.getChunkCount(), 7); + } + + /** + * Test of readHeader method, of class DictZipHeader. + * + * @throws java.lang.Exception if file I/O error occurred. + */ + @Test public void testReadHeader_NonGZip() throws Exception { System.out.println("readHeader / not dictzip file"); byte b[] = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'}; @@ -185,7 +224,7 @@ public class DictZipHeaderTest { DictZipHeader.writeHeader(header, outFile); outFile.close(); String expectedHeader = this.getClass().getResource("/test.header.dz").getFile(); - assertTrue(TestUtils.isFileBinaryEquals(testFile, new File(expectedHeader), 6, 46)); + assertTrue(DictZipFileUtils.isFileBinaryEquals(testFile, new File(expectedHeader), 6, 46)); testFile.deleteOnExit(); } } diff --git a/dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java b/dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java index 52bc340..f2d8490 100644 --- a/dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java +++ b/dictzip-lib/src/test/java/org/dict/zip/DictZipInputStreamTest.java @@ -146,7 +146,7 @@ public class DictZipInputStreamTest { sb.append("\nChunk length = 58315"); sb.append("\nNumber of chunks = 7"); String expResult = sb.toString(); - assertEquals(expResult, header.toString()); + assertEquals(header.toString(), expResult); } } diff --git a/dictzip-lib/src/test/java/org/dict/zip/DictZipOutputStreamTest.java b/dictzip-lib/src/test/java/org/dict/zip/DictZipOutputStreamTest.java index 041072a..de65848 100644 --- a/dictzip-lib/src/test/java/org/dict/zip/DictZipOutputStreamTest.java +++ b/dictzip-lib/src/test/java/org/dict/zip/DictZipOutputStreamTest.java @@ -54,7 +54,7 @@ public class DictZipOutputStreamTest { } catch (IOException e) { r = 1; } - assertEquals(1, r, "DictZip instance can still be used after close is called"); + assertEquals(r, 1, "DictZip instance can still be used after close is called"); } catch (IOException e) { fail("an IO error occurred while trying to find the output file or creating DictZip constructor"); } @@ -129,7 +129,7 @@ public class DictZipOutputStreamTest { } catch (Exception ex) { r = 1; } - assertEquals(1, r, "DictZip instance can still be used after finish is called"); + assertEquals(r, 1, "DictZip instance can still be used after finish is called"); } catch (Exception ex) { fail("an IO error occured while trying to find the output file or creating DictZip constructor"); } diff --git a/dictzip-lib/src/test/java/org/dict/zip/RandomAccessInputStreamTest.java b/dictzip-lib/src/test/java/org/dict/zip/RandomAccessInputStreamTest.java index 29d192b..e8ecfdc 100644 --- a/dictzip-lib/src/test/java/org/dict/zip/RandomAccessInputStreamTest.java +++ b/dictzip-lib/src/test/java/org/dict/zip/RandomAccessInputStreamTest.java @@ -41,7 +41,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); int expResult = 136856; int result = instance.available(); - assertEquals(expResult, result); + assertEquals(result, expResult); } /** @@ -63,7 +63,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); int expResult = 136856; int result = instance.getLength(); - assertEquals(expResult, result); + assertEquals(result, expResult); } /** @@ -75,7 +75,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); int expResult = 0; int result = instance.getPos(); - assertEquals(expResult, result); + assertEquals(result, expResult); } /** @@ -118,7 +118,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); int expResult = 31; int result = instance.read(); - assertEquals(expResult, result); + assertEquals(result, expResult); } catch (Exception ex) { fail("get exception."); } @@ -136,7 +136,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); int expResult = 256; int result = instance.read(b, off, len); - assertEquals(expResult, result); + assertEquals(result, expResult); } /** @@ -181,7 +181,7 @@ public class RandomAccessInputStreamTest { RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r"); long expResult = 100L; long result = instance.skip(n); - assertEquals(expResult, result); + assertEquals(result, expResult); } }