1
2
3
4
5 package com.qulice.pmd;
6
7 import com.google.common.base.Joiner;
8 import com.qulice.spi.Environment;
9 import com.qulice.spi.Violation;
10 import java.io.File;
11 import java.util.Collections;
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19
20
21
22 final class PmdInnerClassConstantsTest {
23
24 @Test
25 void doesNotComplainAboutConstantsInInnerClasses() throws Exception {
26 final String file = "src/main/java/foo/Foo.java";
27 final Environment env = new Environment.Mock().withFile(
28 file,
29 Joiner.on('\n').join(
30 "package foo;",
31 "interface Foo {",
32 " final class Bar implements Foo {",
33 " private static final Pattern TEST =",
34 " Pattern.compile(\"hey\");",
35 " public String doSomething() {",
36 " return Foo.Bar.TEST.toString();",
37 " }",
38 " }",
39 "}"
40 )
41 );
42 MatcherAssert.assertThat(
43 "Private constant in inner class is not a violation",
44 new PmdValidator(env).validate(
45 Collections.singletonList(new File(env.basedir(), file))
46 ),
47 Matchers.<Violation>empty()
48 );
49 }
50 }