1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.junit.Test;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31
32
33
34
35 public class ScmFileSetTest {
36 private static String basedirPath;
37
38 public static String getBasedir() {
39 if (basedirPath != null) {
40 return basedirPath;
41 }
42
43 basedirPath = System.getProperty("basedir");
44
45 if (basedirPath == null) {
46 basedirPath = new File("").getAbsolutePath();
47 }
48
49 return basedirPath;
50 }
51
52 private String removeBasedir(String filename) {
53 return filename.substring(getBasedir().length(), filename.length());
54 }
55
56 @Test
57 public void testFilesList() throws IOException {
58 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**");
59 assertEquals("src", fileSet.getBasedir().getName());
60 assertEquals("**/**", fileSet.getIncludes());
61
62 assertTrue(
63 "List of files should be longer than 10 elements, but received: "
64 + fileSet.getFileList().size(),
65 fileSet.getFileList().size() > 10);
66 }
67
68 @Test
69 public void testFilesListWithoutIncludesResultsEmptyList() throws IOException {
70 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"));
71 assertEquals(0, fileSet.getFileList().size());
72 }
73
74 @Test
75 public void testFilesListExcludes() throws IOException {
76 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**", "**/exclude/**");
77
78 List<File> files = fileSet.getFileList();
79
80 Iterator<File> it = files.iterator();
81 while (it.hasNext()) {
82 File file = (File) it.next();
83 if (removeBasedir(file.getAbsolutePath()).indexOf("exclude") != -1) {
84 fail("Found excludes in file set: " + file);
85 }
86 }
87 }
88
89 @Test
90 public void testFilesListExcludes2() throws IOException {
91 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**", "**/exclude/**");
92
93 assertEquals(2, fileSet.getFileList().size());
94 }
95
96 @Test
97 public void testFilesListNoExcludes() throws IOException {
98 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**");
99
100 assertEquals(4, fileSet.getFileList().size());
101 }
102 }