1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package eu.simuline.m2latex.core;
20
21 import eu.simuline.m2latex.mojo.MavenLogWrapper;
22
23
24
25
26 import java.io.File;
27 import java.io.IOException;
28
29 import static org.junit.Assert.assertEquals;
30
31 import org.junit.Test;
32
33 import org.junit.Before;
34 import org.junit.After;
35
36 public class TexFileUtilsTest {
37 private final static File WORKING_DIR =
38 new File(System.getProperty("unitTestResourcesDir"));
39
40
41
42
43
44 private static void cleanWorkingDir() {
45 cleanDirRec(WORKING_DIR);
46 }
47
48
49 private static void cleanDirRec(File dir) {
50 assert dir.isDirectory() : "Expected directory. ";
51 File[] files = dir.listFiles();
52 assert files != null : "Directory is not readable. ";
53 boolean proof;
54 for (File file : files) {
55 assert file.exists();
56 if (file.isDirectory()) {
57 assert !file.isHidden();
58 cleanDirRec(file);
59 assert file.listFiles().length == 0;
60 }
61 if (!file.isHidden()) {
62 proof = file.delete();
63 assert proof;
64 }
65 }
66 }
67
68 @Before
69 public void setUp() throws IOException {
70 cleanWorkingDir();
71 }
72
73 @After
74 public void tearDown() throws IOException {
75 cleanWorkingDir();
76 }
77
78 @Test
79 public void testGetTargetDir() throws BuildFailureException {
80
81 File expected = new File(WORKING_DIR, "dir2/subdir");
82 TexFileUtils utils =
83 new TexFileUtils(new MavenLogWrapper(this.getClass()));
84
85 File actual =
86 utils.getTargetDirectory(new File(WORKING_DIR, "dir1/subdir/file"),
87 new File(WORKING_DIR, "dir1"), new File(WORKING_DIR, "dir2"));
88 assertEquals(expected, actual);
89 }
90 }