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.SimplifyBooleanExpressionCheck.MSG_KEY;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28
29 public class SimplifyBooleanExpressionCheckTest
30 extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/coding/simplifybooleanexpression";
35 }
36
37 @Test
38 public void testIt() throws Exception {
39 final String[] expected = {
40 "22:18: " + getCheckMessage(MSG_KEY),
41 "43:36: " + getCheckMessage(MSG_KEY),
42 "44:36: " + getCheckMessage(MSG_KEY),
43 "45:16: " + getCheckMessage(MSG_KEY),
44 "45:32: " + getCheckMessage(MSG_KEY),
45 "95:27: " + getCheckMessage(MSG_KEY),
46 "96:24: " + getCheckMessage(MSG_KEY),
47 "98:27: " + getCheckMessage(MSG_KEY),
48 "104:23: " + getCheckMessage(MSG_KEY),
49 "106:17: " + getCheckMessage(MSG_KEY),
50 "109:21: " + getCheckMessage(MSG_KEY),
51 "110:23: " + getCheckMessage(MSG_KEY),
52 "111:20: " + getCheckMessage(MSG_KEY),
53 };
54 verifyWithInlineConfigParser(
55 getPath("InputSimplifyBooleanExpression.java"), expected);
56 }
57
58 @Test
59 public void testWhenExpression() throws Exception {
60 final String[] expected = {
61 "13:41: " + getCheckMessage(MSG_KEY),
62 "16:41: " + getCheckMessage(MSG_KEY),
63 "17:41: " + getCheckMessage(MSG_KEY),
64 "22:41: " + getCheckMessage(MSG_KEY),
65 "23:44: " + getCheckMessage(MSG_KEY),
66 };
67 verifyWithInlineConfigParser(
68 getNonCompilablePath("InputSimplifyBooleanExpressionWithWhen.java"), expected);
69 }
70
71 @Test
72 public void testTokensNotNull() {
73 final SimplifyBooleanExpressionCheck check = new SimplifyBooleanExpressionCheck();
74 assertWithMessage("Acceptable tokens should not be null")
75 .that(check.getAcceptableTokens())
76 .isNotNull();
77 assertWithMessage("Default tokens should not be null")
78 .that(check.getDefaultTokens())
79 .isNotNull();
80 assertWithMessage("Required tokens should not be null")
81 .that(check.getRequiredTokens())
82 .isNotNull();
83 }
84
85 }