OSDN Git Service

95d68cccdab1ad142f3fe3e62d7b3a236eef8a9f
[dictzip-java/dictzip-java.git] / dictzip-lib / src / test / java / org / dict / zip / DictZipFileUtilsTest.java
1 package org.dict.zip;
2
3 import org.junit.jupiter.api.Assertions;
4 import org.junit.jupiter.api.Test;
5
6 import java.io.IOException;
7
8 import static org.junit.jupiter.api.Assertions.assertTrue;
9
10 public class DictZipFileUtilsTest {
11
12     /**
13      * Check dictzip inputstream.
14      * @throws Exception when fails.
15      */
16     @Test
17     public void testCheckDictZipInputStreamString() throws Exception {
18         String targetFile = this.getClass().getResource("/test.dict.dz").getFile();
19         Assertions.assertTrue(DictZipFileUtils.checkDictZipInputStream(targetFile));
20     }
21
22     /**
23      * Check dictzip input streasm which is not exist.
24      */
25     @Test
26     public void testCheckDictZipInputStreamStringNoExist() {
27         String targetFile = "false.dict.dz";
28         boolean result;
29         try {
30             DictZipFileUtils.checkDictZipInputStream(targetFile);
31             result = false;
32         } catch (IOException e) {
33             // expected.
34             result = true;
35         }
36         assertTrue(result);
37     }
38
39     /**
40      * Check dictzip input stream.
41      * @throws Exception when fails.
42      */
43     @Test
44     public void testCheckDictZipInputStream() throws Exception {
45         String targetFile = this.getClass().getResource("/test.dict.dz").getFile();
46         try (DictZipInputStream dzin = new DictZipInputStream(new
47                 RandomAccessInputStream(targetFile, "r"))) {
48             Assertions.assertTrue(DictZipFileUtils.checkDictZipInputStream(dzin));
49         }
50     }
51 }