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 @SuppressWarnings("PMD.TooManyMethods")
15 final class PmdEmptyTest {
16
17
18
19
20 @Test
21 void failsForEmptyStaticInitializer() throws Exception {
22 new PmdAssert(
23 "EmptyStaticInitializer.java",
24 Matchers.is(false),
25 Matchers.containsString(
26 "Empty initializer statement (EmptyControlStatement)"
27 )
28 ).validate();
29 }
30
31
32
33
34
35 @Test
36 void failsForEmptyStatementBlock() throws Exception {
37 new PmdAssert(
38 "EmptyStatementBlock.java",
39 Matchers.is(false),
40 Matchers.containsString(
41 "Empty block "
42 )
43 ).validate();
44 }
45
46
47
48
49
50 @Test
51 void failsForEmptyInitializer() throws Exception {
52 new PmdAssert(
53 "EmptyInitializer.java",
54 Matchers.is(false),
55 Matchers.containsString(
56 "Empty initializer statement "
57 )
58 ).validate();
59 }
60
61
62
63
64
65 @Test
66 void failsForEmptyNonLoopStatement() throws Exception {
67 new PmdAssert(
68 "EmptyStatementNotInLoop.java",
69 Matchers.is(false),
70 Matchers.containsString(
71 "Unnecessary semicolon "
72 )
73 ).validate();
74 }
75
76
77
78
79
80 @Test
81 void failsForEmptySynchronizedBlock() throws Exception {
82 new PmdAssert(
83 "EmptySynchronizedBlock.java",
84 Matchers.is(false),
85 Matchers.containsString(
86 "Empty synchronized statement "
87 )
88 ).validate();
89 }
90
91
92
93
94
95 @Test
96 void failsForEmptySwitchStatement() throws Exception {
97 new PmdAssert(
98 "EmptySwitchStmt.java",
99 Matchers.is(false),
100 Matchers.containsString(
101 "Empty switch statement "
102 )
103 ).validate();
104 }
105
106
107
108
109
110 @Test
111 void failsForEmptyFinallyBlock() throws Exception {
112 new PmdAssert(
113 "EmptyFinallyBlock.java",
114 Matchers.is(false),
115 Matchers.containsString("Empty finally clause")
116 ).validate();
117 }
118
119
120
121
122
123 @Test
124 void failsForEmptyWhileStatement() throws Exception {
125 new PmdAssert(
126 "EmptyWhileStmt.java",
127 Matchers.is(false),
128 Matchers.containsString("Empty while statement ")
129 ).validate();
130 }
131
132
133
134
135
136 @Test
137 void failsForEmptyIfStatement() throws Exception {
138 new PmdAssert(
139 "EmptyIfStmt.java",
140 Matchers.is(false),
141 Matchers.containsString("Empty if statement ")
142 ).validate();
143 }
144
145
146
147
148
149 @Test
150 void failsForEmptyCatchBlock() throws Exception {
151 new PmdAssert(
152 "EmptyCatchBlock.java",
153 Matchers.is(false),
154 Matchers.containsString("Avoid empty catch blocks")
155 ).validate();
156 }
157 }