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 protected 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 getNonCompilablePath("InputUnnecessarySemicolonAfterOuterTypeDeclarationRecords.java"),
65 expected);
66 }
67
68 @Test
69 public void testTokens() {
70 final UnnecessarySemicolonAfterOuterTypeDeclarationCheck check =
71 new UnnecessarySemicolonAfterOuterTypeDeclarationCheck();
72 final int[] expected = {
73 TokenTypes.CLASS_DEF,
74 TokenTypes.INTERFACE_DEF,
75 TokenTypes.ENUM_DEF,
76 TokenTypes.ANNOTATION_DEF,
77 TokenTypes.RECORD_DEF,
78 };
79 assertWithMessage("Acceptable required tokens are invalid")
80 .that(check.getAcceptableTokens())
81 .isEqualTo(expected);
82 assertWithMessage("Default required tokens are invalid")
83 .that(check.getDefaultTokens())
84 .isEqualTo(expected);
85 assertWithMessage("Required required tokens are invalid")
86 .that(check.getRequiredTokens())
87 .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
88 }
89 }