1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.codehaus.plexus.archiver;
25
26 import java.io.File;
27
28 import org.codehaus.plexus.archiver.tar.TarArchiver;
29 import org.codehaus.plexus.archiver.tar.TarLongFileMode;
30 import org.junit.jupiter.api.Test;
31
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33
34
35
36
37 class EmptyDirectoryTest extends TestSupport {
38
39 @Test
40 void testZipArchiver() throws Exception {
41 testEmptyDirectory("zip", lookup(Archiver.class, "zip"));
42 }
43
44 @Test
45 void testJarArchiver() throws Exception {
46
47
48 }
49
50 @Test
51 void testTarArchiver() throws Exception {
52 final TarArchiver tar = (TarArchiver) lookup(Archiver.class, "tar");
53 tar.setLongfile(TarLongFileMode.posix);
54 testEmptyDirectory("tar", tar);
55 }
56
57 private void testEmptyDirectory(String role, Archiver archiver) throws Exception {
58
59
60 assertTrue(archiver.getIncludeEmptyDirs());
61
62
63 File emptyDir = getTestFile("target/output/emptyTest/TmpEmptyDir");
64
65
66 if (emptyDir.exists()) {
67 emptyDir.delete();
68 }
69 emptyDir.mkdirs();
70 archiver.addDirectory(emptyDir.getParentFile());
71
72 File archive = getTestFile("target/output/emptyDirArchive.zip");
73 if (archive.exists()) {
74 archive.delete();
75 }
76
77 archiver.setDestFile(archive);
78 archiver.createArchive();
79
80
81 emptyDir.delete();
82
83
84 UnArchiver unArchiver = lookup(UnArchiver.class, role);
85 unArchiver.setSourceFile(archive);
86
87 unArchiver.setDestDirectory(getTestFile("target/output/emptyTest"));
88 unArchiver.extract();
89
90 assertTrue(emptyDir.exists());
91 assertTrue(emptyDir.isDirectory());
92 }
93 }