1
2
3
4
5 package com.qulice.pmd;
6
7 import org.hamcrest.Matchers;
8 import org.junit.jupiter.api.Test;
9 import org.junit.jupiter.params.ParameterizedTest;
10 import org.junit.jupiter.params.provider.ValueSource;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 final class PmdTooManyMethodsTest {
28
29 @ParameterizedTest
30 @ValueSource(
31 strings = {
32 "ManyMethodsTest.java",
33 "ManyMethodsIT.java",
34 "ManyMethodsNestedTest.java",
35 "ManyMethodsChecks.java",
36 "ManyPublicMethodsTest.java"
37 }
38 )
39 void allowsManyMethodsInTestClass(final String file) throws Exception {
40 new PmdAssert(
41 file,
42 Matchers.any(Boolean.class),
43 Matchers.not(
44 Matchers.containsString("TooManyMethods")
45 )
46 ).assertOk();
47 }
48
49 @Test
50 void reportsTooManyMethodsInNonTestClass() throws Exception {
51 new PmdAssert(
52 "ManyMethods.java",
53 Matchers.is(false),
54 Matchers.containsString("TooManyMethods")
55 ).assertOk();
56 }
57
58 @Test
59 void reportsTooManyProtectedMethods() throws Exception {
60 new PmdAssert(
61 "ManyProtectedMethods.java",
62 Matchers.is(false),
63 Matchers.containsString("TooManyMethods")
64 ).assertOk();
65 }
66
67 @Test
68 void ignoresPrivateMethods() throws Exception {
69 new PmdAssert(
70 "ManyPrivateMethods.java",
71 Matchers.any(Boolean.class),
72 Matchers.not(
73 Matchers.containsString("TooManyMethods")
74 )
75 ).assertOk();
76 }
77
78 @Test
79 void ignoresOverriddenMethods() throws Exception {
80 new PmdAssert(
81 "ManyOverriddenMethods.java",
82 Matchers.any(Boolean.class),
83 Matchers.not(
84 Matchers.containsString("TooManyMethods")
85 )
86 ).assertOk();
87 }
88
89 @ParameterizedTest
90 @ValueSource(
91 strings = {
92 "JnaLibrary.java",
93 "JnaQualifiedLibrary.java",
94 "JnaDirectLibrary.java",
95 "StdCallLibraryMethods.java"
96 }
97 )
98 void allowsManyMethodsInJnaBinding(final String file) throws Exception {
99 new PmdAssert(
100 file,
101 Matchers.any(Boolean.class),
102 Matchers.not(
103 Matchers.containsString("TooManyMethods")
104 )
105 ).assertOk();
106 }
107
108 @Test
109 void reportsTooManyMethodsInPlainInterface() throws Exception {
110 new PmdAssert(
111 "ManyMethodsInterface.java",
112 Matchers.is(false),
113 Matchers.containsString("TooManyMethods")
114 ).assertOk();
115 }
116
117 @Test
118 void reportsRedundantSuppressionInTestClass() throws Exception {
119 new PmdAssert(
120 "ManyMethodsSuppressedTest.java",
121 Matchers.is(false),
122 Matchers.containsString("UnnecessaryWarningSuppression")
123 ).assertOk();
124 }
125 }