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.whitespace;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCaseDefaultColonCheck.MSG_KEY;
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
30 public class NoWhitespaceBeforeCaseDefaultColonCheckTest
31 extends AbstractModuleTestSupport {
32
33 @Override
34 protected String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/whitespace"
36 + "/nowhitespacebeforecasedefaultcolon";
37 }
38
39 @Test
40 public void testDefault() throws Exception {
41 createModuleConfig(
42 NoWhitespaceBeforeCaseDefaultColonCheck.class);
43 final String[] expected = {
44 "15:20: " + getCheckMessage(MSG_KEY, ":"),
45 "19:21: " + getCheckMessage(MSG_KEY, ":"),
46 "32:37: " + getCheckMessage(MSG_KEY, ":"),
47 "40:21: " + getCheckMessage(MSG_KEY, ":"),
48 "44:28: " + getCheckMessage(MSG_KEY, ":"),
49 "47:1: " + getCheckMessage(MSG_KEY, ":"),
50 "50:27: " + getCheckMessage(MSG_KEY, ":"),
51 "61:38: " + getCheckMessage(MSG_KEY, ":"),
52 "66:38: " + getCheckMessage(MSG_KEY, ":"),
53 "79:24: " + getCheckMessage(MSG_KEY, ":"),
54 "82:21: " + getCheckMessage(MSG_KEY, ":"),
55 "89:38: " + getCheckMessage(MSG_KEY, ":"),
56 "92:35: " + getCheckMessage(MSG_KEY, ":"),
57 };
58 verifyWithInlineConfigParser(
59 getPath("InputNoWhitespaceBeforeCaseDefaultColon.java"),
60 expected);
61 }
62
63 @Test
64 public void testDefaultNonCompilable() throws Exception {
65 createModuleConfig(
66 NoWhitespaceBeforeCaseDefaultColonCheck.class);
67 final String[] expected = {
68 "36:22: " + getCheckMessage(MSG_KEY, ":"),
69 "39:21: " + getCheckMessage(MSG_KEY, ":"),
70 "42:25: " + getCheckMessage(MSG_KEY, ":"),
71 "61:20: " + getCheckMessage(MSG_KEY, ":"),
72 "74:32: " + getCheckMessage(MSG_KEY, ":"),
73 "91:17: " + getCheckMessage(MSG_KEY, ":"),
74 "94:20: " + getCheckMessage(MSG_KEY, ":"),
75 "97:21: " + getCheckMessage(MSG_KEY, ":"),
76 };
77 verifyWithInlineConfigParser(
78 getNonCompilablePath("InputNoWhitespaceBeforeCaseDefaultColonEnumAndStrings.java"),
79 expected);
80 }
81
82 @Test
83 public void testAcceptableTokenIsColon() {
84 final NoWhitespaceBeforeCaseDefaultColonCheck check =
85 new NoWhitespaceBeforeCaseDefaultColonCheck();
86 assertWithMessage("Acceptable token should be colon")
87 .that(new int[] {TokenTypes.COLON})
88 .isEqualTo(check.getAcceptableTokens());
89 }
90
91 @Test
92 public void testPatternMatchingForSwitch() throws Exception {
93 final String[] expected = {
94 "14:62: " + getCheckMessage(MSG_KEY, ":"),
95 "16:21: " + getCheckMessage(MSG_KEY, ":"),
96 "18:21: " + getCheckMessage(MSG_KEY, ":"),
97 "20:67: " + getCheckMessage(MSG_KEY, ":"),
98 "23:36: " + getCheckMessage(MSG_KEY, ":"),
99 "25:21: " + getCheckMessage(MSG_KEY, ":"),
100 };
101 verifyWithInlineConfigParser(
102 getNonCompilablePath(
103 "InputNoWhitespaceBeforeCaseDefaultColonPatternMatchingForSwitch.java"),
104 expected);
105 }
106
107 }