1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.annotation;
21
22 import org.junit.jupiter.api.Test;
23
24 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
25 import com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck;
26 import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
27 import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
28 import com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck;
29
30 public class SuppressWarningsHolderExamplesTest extends AbstractExamplesModuleTestSupport {
31
32 @Override
33 public String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/annotation/suppresswarningsholder";
35 }
36
37 @Test
38 public void testExample1() throws Exception {
39 final String pattern1 = "^[a-z][a-zA-Z0-9]*$";
40 final String[] expected = {
41 "20:15: " + getCheckMessage(MemberNameCheck.class,
42 AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern1),
43 "28:15: " + getCheckMessage(NoWhitespaceAfterCheck.class,
44 NoWhitespaceAfterCheck.MSG_KEY, "int"),
45 "28:18: " + getCheckMessage(MemberNameCheck.class,
46 AbstractNameCheck.MSG_INVALID_PATTERN, "ARR", pattern1),
47 "34:17: " + getCheckMessage(ParameterNumberCheck.class,
48 ParameterNumberCheck.MSG_KEY, 7, 8),
49
50 };
51
52 verifyWithInlineConfigParser(getPath("Example1.java"), expected);
53 }
54
55 @Test
56 public void testExample2() throws Exception {
57 final String pattern1 = "^[a-z][a-zA-Z0-9]*$";
58 final String[] expected = {
59 "24:15: " + getCheckMessage(MemberNameCheck.class,
60 AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern1),
61 "32:15: " + getCheckMessage(NoWhitespaceAfterCheck.class,
62 NoWhitespaceAfterCheck.MSG_KEY, "int"),
63 "32:18: " + getCheckMessage(MemberNameCheck.class,
64 AbstractNameCheck.MSG_INVALID_PATTERN, "ARR", pattern1),
65 };
66
67 verifyWithInlineConfigParser(getPath("Example2.java"), expected);
68 }
69
70 @Test
71 public void testUseCase1() throws Exception {
72 final String[] expected = {
73 "29:15: " + getCheckMessage(ParameterNumberCheck.class,
74 ParameterNumberCheck.MSG_KEY, 7, 8),
75 "35:15: " + getCheckMessage(ParameterNumberCheck.class,
76 ParameterNumberCheck.MSG_KEY, 7, 8),
77 };
78
79 verifyWithInlineConfigParser(getPath("UseCase1.java"), expected);
80 }
81
82 @Test
83 public void testUseCase2() throws Exception {
84 final String[] expected = {
85 "29:15: " + getCheckMessage(ParameterNumberCheck.class,
86 ParameterNumberCheck.MSG_KEY, 7, 8),
87 "35:15: " + getCheckMessage(ParameterNumberCheck.class,
88 ParameterNumberCheck.MSG_KEY, 7, 8),
89 };
90
91 verifyWithInlineConfigParser(getPath("UseCase2.java"), expected);
92 }
93
94 }