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 final class PmdPublicStaticMethodTest {
18
19
20
21
22 private static final String STATIC_METHODS =
23 "Public static methods are prohibited";
24
25 @Test
26 void prohibitsPublicStaticMethods() throws Exception {
27 new PmdAssert(
28 "StaticPublicMethod.java",
29 Matchers.is(false),
30 Matchers.containsString(PmdPublicStaticMethodTest.STATIC_METHODS)
31 ).assertOk();
32 }
33
34 @Test
35 void allowsPublicStaticMainMethod() throws Exception {
36 new PmdAssert(
37 "StaticPublicVoidMainMethod.java",
38 Matchers.is(true),
39 Matchers.not(
40 Matchers.containsString(PmdPublicStaticMethodTest.STATIC_METHODS)
41 )
42 ).assertOk();
43 }
44
45 @Test
46 void allowsJunitFrameworkPublicStaticMethods() throws Exception {
47 new PmdAssert(
48 "JunitStaticPublicMethods.java",
49 Matchers.is(false),
50 Matchers.allOf(
51 Matchers.not(
52 Matchers.containsString(PmdPublicStaticMethodTest.STATIC_METHODS)
53 ),
54 Matchers.containsString("UnitTestShouldIncludeAssert")
55 )
56 ).assertOk();
57 }
58 }