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 import eu.simuline.m2latex.core.BuildExecutionException;
24 import eu.simuline.m2latex.core.BuildFailureException;
25
26 import org.apache.maven.plugin.logging.SystemStreamLog;
27
28 import java.io.File;
29 import java.io.IOException;
30
31 import static org.junit.Assert.assertEquals;
32
33 import org.junit.Test;
34 import org.junit.Ignore;
35 import org.junit.Before;
36 import org.junit.After;
37
38 public class TexFileUtilsTest {
39 private final static File WORKING_DIR =
40 new File(System.getProperty("testResourcesDir"));
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 public void setUp() throws IOException {
69 cleanWorkingDir();
70 }
71
72 @After public void tearDown() throws IOException {
73 cleanWorkingDir();
74 }
75
76
77
78 @Test public void testGetTargetDir() throws BuildFailureException {
79
80 File expected = new File(WORKING_DIR, "dir2/subdir");
81 TexFileUtils utils =
82 new TexFileUtils(new MavenLogWrapper(new SystemStreamLog()));
83
84 File actual = utils
85 .getTargetDirectory(new File(WORKING_DIR, "dir1/subdir/file"),
86 new File(WORKING_DIR, "dir1"),
87 new File(WORKING_DIR, "dir2"));
88 assertEquals(expected, actual);
89 }
90 }