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