1
2
3
4
5 package com.qulice.pmd;
6
7 import org.hamcrest.Matchers;
8 import org.junit.jupiter.api.Test;
9
10
11
12
13
14
15
16
17
18
19
20
21 final class PmdTooManyFieldsTest {
22
23 @Test
24 void doesNotFireOnMojoWithManyFields() throws Exception {
25 new PmdAssert(
26 "TooManyFieldsInMojo.java",
27 Matchers.any(Boolean.class),
28 Matchers.not(
29 Matchers.containsString("(TooManyFields)")
30 )
31 ).assertOk();
32 }
33
34 @Test
35 void firesOnPlainClassWithManyFields() throws Exception {
36 new PmdAssert(
37 "TooManyFieldsInPlainClass.java",
38 Matchers.is(false),
39 Matchers.containsString("(TooManyFields)")
40 ).assertOk();
41 }
42
43 @Test
44 void ignoresConstants() throws Exception {
45 new PmdAssert(
46 "TooManyFieldsInConstants.java",
47 Matchers.any(Boolean.class),
48 Matchers.not(
49 Matchers.containsString("(TooManyFields)")
50 )
51 ).assertOk();
52 }
53
54 @Test
55 void reportsRedundantSuppressionOnMojo() throws Exception {
56 new PmdAssert(
57 "TooManyFieldsSuppressedInMojo.java",
58 Matchers.is(false),
59 Matchers.containsString("(UnnecessaryWarningSuppression)")
60 ).assertOk();
61 }
62
63 @Test
64 void honoursSuppressionOnPlainClass() throws Exception {
65 new PmdAssert(
66 "TooManyFieldsSuppressedInPlainClass.java",
67 Matchers.any(Boolean.class),
68 Matchers.allOf(
69 Matchers.not(Matchers.containsString("(TooManyFields)")),
70 Matchers.not(
71 Matchers.containsString("(UnnecessaryWarningSuppression)")
72 )
73 )
74 ).assertOk();
75 }
76 }