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.MultipleVariableDeclarationsCheck.MSG_MULTIPLE;
24 import static com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck.MSG_MULTIPLE_COMMA;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29
30 public class MultipleVariableDeclarationsCheckTest extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations";
35 }
36
37 @Test
38 public void testIt() throws Exception {
39
40 final String[] expected = {
41 "11:5: " + getCheckMessage(MSG_MULTIPLE_COMMA),
42 "12:5: " + getCheckMessage(MSG_MULTIPLE),
43 "15:9: " + getCheckMessage(MSG_MULTIPLE_COMMA),
44 "16:9: " + getCheckMessage(MSG_MULTIPLE),
45 "20:5: " + getCheckMessage(MSG_MULTIPLE),
46 "23:5: " + getCheckMessage(MSG_MULTIPLE),
47 "42:9: " + getCheckMessage(MSG_MULTIPLE),
48 "42:31: " + getCheckMessage(MSG_MULTIPLE),
49 "42:44: " + getCheckMessage(MSG_MULTIPLE),
50 };
51
52 verifyWithInlineConfigParser(
53 getPath("InputMultipleVariableDeclarations.java"),
54 expected);
55 }
56
57 @Test
58 public void testTokensNotNull() {
59 final MultipleVariableDeclarationsCheck check = new MultipleVariableDeclarationsCheck();
60 assertWithMessage("Acceptable tokens should not be null")
61 .that(check.getAcceptableTokens())
62 .isNotNull();
63 assertWithMessage("Default tokens should not be null")
64 .that(check.getDefaultTokens())
65 .isNotNull();
66 assertWithMessage("Required tokens should not be null")
67 .that(check.getRequiredTokens())
68 .isNotNull();
69 }
70
71 @Test
72 public void test() throws Exception {
73
74 final String[] expected = {
75 "11:5: " + getCheckMessage(MSG_MULTIPLE),
76 "14:5: " + getCheckMessage(MSG_MULTIPLE),
77 };
78
79 verifyWithInlineConfigParser(
80 getPath("InputMultipleVariableDeclarations2.java"),
81 expected);
82 }
83
84 @Test
85 public void testUnnamedVariables() throws Exception {
86
87 final String[] expected = {
88 "12:9: " + getCheckMessage(MSG_MULTIPLE_COMMA),
89 "14:9: " + getCheckMessage(MSG_MULTIPLE_COMMA),
90 "16:9: " + getCheckMessage(MSG_MULTIPLE),
91 "18:9: " + getCheckMessage(MSG_MULTIPLE),
92 };
93
94 verifyWithInlineConfigParser(
95 getNonCompilablePath("InputMultipleVariableDeclarationsUnnamedVariables.java"),
96 expected);
97 }
98
99 }