1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package com.qulice.maven;
32
33 import com.google.common.collect.ImmutableList;
34 import java.nio.charset.StandardCharsets;
35 import java.util.Collections;
36 import org.apache.maven.project.MavenProject;
37 import org.hamcrest.MatcherAssert;
38 import org.hamcrest.Matchers;
39 import org.junit.jupiter.api.Test;
40 import org.mockito.Mockito;
41
42
43
44
45
46 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
47 final class DefaultMavenEnvironmentTest {
48
49
50
51
52 @Test
53 void excludeAllFiles() {
54 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
55 env.setExcludes(Collections.singletonList("codenarc:**/*.groovy"));
56 MatcherAssert.assertThat(
57 "Excludes should be returned",
58 env.excludes("codenarc"),
59 Matchers.contains("**/*.groovy")
60 );
61 }
62
63
64
65
66 @Test
67 void emptyExclude() {
68 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
69 env.setExcludes(Collections.<String>emptyList());
70 MatcherAssert.assertThat(
71 "Empty list should be returned",
72 env.excludes("codenarc").iterator().hasNext(),
73 Matchers.is(false)
74 );
75 }
76
77
78
79
80 @Test
81 void noExclude() {
82 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
83 MatcherAssert.assertThat(
84 "Excludes should be empty list by default",
85 env.excludes("codenarc").iterator().hasNext(),
86 Matchers.is(false)
87 );
88 }
89
90
91
92
93 @Test
94 void excludeSomeFiles() {
95 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
96 env.setExcludes(
97 ImmutableList.<String>builder()
98 .add("codenarc:**/src/ex1/Main.groovy")
99 .add("codenarc:**/src/ex2/Main2.groovy")
100 .build()
101 );
102 MatcherAssert.assertThat(
103 "Excludes should be returned as list",
104 env.excludes("codenarc"),
105 Matchers.containsInAnyOrder(
106 "**/src/ex1/Main.groovy",
107 "**/src/ex2/Main2.groovy"
108 )
109 );
110 }
111
112
113
114
115
116 @Test
117 void passPathsWithWhitespaces() throws Exception {
118 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
119 final MavenProject project = Mockito.mock(MavenProject.class);
120 Mockito.when(project.getRuntimeClasspathElements())
121 .thenReturn(
122 Collections.singletonList("/Users/Carlos Miranda/git")
123 );
124 env.setProject(project);
125 MatcherAssert.assertThat(
126 "ClassPath should be returned",
127 env.classloader(),
128 Matchers.notNullValue()
129 );
130 }
131
132
133
134
135
136 @Test
137 void producesEmptyExcludesWhenNoMatches() {
138 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
139 env.setExcludes(
140 ImmutableList.of(
141 "checkstyle:**/src/ex1/Main.groovy",
142 "pmd:**/src/ex2/Main2.groovy"
143 )
144 );
145 MatcherAssert.assertThat(
146 "Exclude dependencies should be empty",
147 env.excludes("dependencies"),
148 Matchers.empty()
149 );
150 }
151
152
153
154
155 @Test
156 void defaultEncodingIsUtf() {
157 final DefaultMavenEnvironment env = new DefaultMavenEnvironment();
158 MatcherAssert.assertThat(
159 "Default encoding should be UTF-8",
160 env.encoding(),
161 Matchers.is(StandardCharsets.UTF_8)
162 );
163 }
164 }