1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.tunyk.mvn.plugins.htmlcompressor;
20
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.json.JSONException;
26 import org.junit.jupiter.api.AfterAll;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37 class FileToolTest {
38
39
40 private static final Logger LOG = LoggerFactory.getLogger(FileToolTest.class);
41
42
43
44
45 @BeforeAll
46 static void setUpClass() {
47 LOG.info("Setting up class...");
48 }
49
50
51
52
53 @AfterAll
54 static void tearDownClass() {
55 LOG.info("Test finished.");
56 }
57
58
59
60
61 @BeforeEach
62 void setUp() {
63 LOG.info("Setting up data for testing...");
64 }
65
66
67
68
69
70
71
72 @Test
73 void testGetFiles() throws IOException {
74 LOG.info("Testing getFiles method...");
75
76 FileTool fileTool = new FileTool("src/test/resources/html", new String[] { "htm", "html" }, true);
77 Map<String, String> map = fileTool.getFiles();
78
79 Assertions.assertTrue(map.containsKey("templates/Template1.html"));
80 Assertions.assertTrue(map.containsKey("templates/Template2.html"));
81 Assertions.assertTrue(map.containsKey("templates/recursive/Template.html"));
82
83
84
85
86
87
88 LOG.info("Passed");
89 }
90
91
92
93
94
95
96
97 @Test
98 void testWriteFiles() throws IOException {
99 LOG.info("Testing writeFiles method...");
100
101 String targetDir = "target/test/filetool";
102 FileTool fileTool = new FileTool(targetDir, new String[] { "htm", "html" }, true);
103 Map<String, String> map = new HashMap<String, String>();
104 map.put("file.html", "root file");
105 map.put("/file2.html", "another root file");
106 map.put("file3.html/", "another root file like folder");
107 map.put("/template/file.html", "template file");
108 map.put("template/file01.html", "template file 01");
109 map.put("/template/subfolder/file.html", "template subfolder file");
110 fileTool.writeFiles(map, targetDir);
111
112 Map<String, String> files = fileTool.getFiles();
113 Assertions.assertTrue(files.containsKey("file.html"));
114 Assertions.assertTrue(files.containsKey("file2.html"));
115 Assertions.assertTrue(files.containsKey("file3.html"));
116 Assertions.assertTrue(files.containsKey("template/file.html"));
117 Assertions.assertTrue(files.containsKey("template/file01.html"));
118 Assertions.assertTrue(files.containsKey("template/subfolder/file.html"));
119
120
121
122 LOG.info("Passed");
123 }
124
125
126
127
128
129
130
131
132
133 @Test
134 void testWriteToJsonFile() throws IOException, JSONException {
135 LOG.info("Testing writeToJsonFile method...");
136
137 String targetDir = "target/test/filetool/";
138 String targetFile = targetDir + "json.js";
139 FileTool fileTool = new FileTool(targetDir, new String[] { "htm", "html" }, true);
140 Map<String, String> map = new HashMap<String, String>();
141 map.put("file.html", "root file");
142 map.put("template/file.html", "template file");
143 map.put("template/subfolder/file.html", "template subfolder file");
144 fileTool.writeToJsonFile(map, targetFile, "var templates = %s;");
145
146
147
148 LOG.info("Passed");
149 }
150 }