/
ZipUtilsTest.java
66 lines (54 loc) · 1.76 KB
/
ZipUtilsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.blankj.utilcode.util;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static com.blankj.utilcode.util.TestConfig.PATH_TEMP;
import static com.blankj.utilcode.util.TestConfig.PATH_ZIP;
import static junit.framework.TestCase.assertTrue;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/09/10
* desc : test ZipUtils
* </pre>
*/
public class ZipUtilsTest extends BaseTest {
private String zipFile = PATH_TEMP + "zipFile.zip";
private String zipFiles = PATH_TEMP + "zipFiles.zip";
@Before
public void setUp() throws Exception {
FileUtils.createOrExistsDir(PATH_TEMP);
assertTrue(ZipUtils.zipFile(PATH_ZIP, zipFile, "测试zip"));
}
@Test
public void zipFiles() throws Exception {
List<String> files = new ArrayList<>();
files.add(PATH_ZIP + "test.txt");
files.add(PATH_ZIP);
files.add(PATH_ZIP + "testDir");
assertTrue(ZipUtils.zipFiles(files, zipFiles));
}
@Test
public void unzipFile() throws Exception {
System.out.println(ZipUtils.unzipFile(zipFile, PATH_TEMP));
}
@Test
public void unzipFileByKeyword() throws Exception {
System.out.println((ZipUtils.unzipFileByKeyword(zipFile, PATH_TEMP, null)).toString());
}
@Test
public void getFilesPath() throws Exception {
System.out.println(ZipUtils.getFilesPath(zipFile));
}
@Test
public void getComments() throws Exception {
System.out.println(ZipUtils.getComments(zipFile));
}
@After
public void tearDown() {
FileUtils.deleteAllInDir(PATH_TEMP);
}
}