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