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;
int number = random.nextInt(94);
writer.print((char) (32 + number));
}
- };
+ }
}
void prepareLargeTextData(final Path outTextPath, final int size) throws IOException {
/**
* 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;
/**
* 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,
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;
* 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;
import static org.junit.jupiter.api.Assertions.assertTrue;
+/**
+ * Test of DictZipFileUtils.
+ * @author Hiroshi Miura
+ */
public class DictZipFileUtilsTest {
/**
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;
/**
/**
* 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);
/**
* 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);
/**
* 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);
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();
}
}
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;
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.
@Test
public void testConstructorDefaultBufSize() throws Exception {
try (DictZipInputStream din = new DictZipInputStream(new RandomAccessInputStream(dataFile, "r"))) {
- // pass
+ assertNotNull(din);
}
}
@Test
public void testConstructorFromFilename() throws Exception {
try (DictZipInputStream din = new DictZipInputStream(dataFile)) {
- // pass
+ assertNotNull(din);
}
}
}
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));
}
}
}
/**
* 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();
/**
* 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(
/**
* 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 {
/**
* 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 {
*/
public final class FileUtils2 {
+ private FileUtils2() { }
+
/**
* Compare file contents in range. Both files must be files (not directories) and exist.
*