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.coding;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.coding.UnnecessarySemicolonAfterOuterTypeDeclarationCheck.MSG_SEMI;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30
31 public class UnnecessarySemicolonAfterOuterTypeDeclarationCheckTest
32 extends AbstractModuleTestSupport {
33
34 @Override
35 public String getPackageLocation() {
36 return "com/puppycrawl/tools/checkstyle/checks/coding/"
37 + "unnecessarysemicolonafteroutertypedeclaration";
38 }
39
40 @Test
41 public void testDefault() throws Exception {
42
43 final String[] expected = {
44 "28:2: " + getCheckMessage(MSG_SEMI),
45 "32:2: " + getCheckMessage(MSG_SEMI),
46 "36:2: " + getCheckMessage(MSG_SEMI),
47 "40:2: " + getCheckMessage(MSG_SEMI),
48 };
49
50 verifyWithInlineConfigParser(
51 getPath("InputUnnecessarySemicolonAfterOuterTypeDeclaration.java"),
52 expected);
53 }
54
55 @Test
56 public void testUnnecessarySemicolonAfterOuterTypeDeclarationRecords() throws Exception {
57
58 final String[] expected = {
59 "17:2: " + getCheckMessage(MSG_SEMI),
60 "23:2: " + getCheckMessage(MSG_SEMI),
61 };
62
63 verifyWithInlineConfigParser(
64 getPath("InputUnnecessarySemicolonAfterOuterTypeDeclarationRecords.java"),
65 expected);
66 }
67
68 @Test
69 public void testCompactSourceFile() throws Exception {
70 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
71
72 verifyWithInlineConfigParser(
73 getNonCompilablePath(
74 "InputUnnecessarySemicolonAfterOuterTypeDeclarationCompactSourceFile.java"),
75 expected);
76 }
77
78 @Test
79 public void testTokens() {
80 final UnnecessarySemicolonAfterOuterTypeDeclarationCheck check =
81 new UnnecessarySemicolonAfterOuterTypeDeclarationCheck();
82 final int[] expected = {
83 TokenTypes.CLASS_DEF,
84 TokenTypes.INTERFACE_DEF,
85 TokenTypes.ENUM_DEF,
86 TokenTypes.ANNOTATION_DEF,
87 TokenTypes.RECORD_DEF,
88 };
89 assertWithMessage("Acceptable required tokens are invalid")
90 .that(check.getAcceptableTokens())
91 .isEqualTo(expected);
92 assertWithMessage("Default required tokens are invalid")
93 .that(check.getDefaultTokens())
94 .isEqualTo(expected);
95 assertWithMessage("Required required tokens are invalid")
96 .that(check.getRequiredTokens())
97 .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
98 }
99
100 }