View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }