View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_INFIX;
24  import static com.puppycrawl.tools.checkstyle.checks.NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_PREFIX;
25  import static com.puppycrawl.tools.checkstyle.checks.NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_SUFFIX;
26  
27  import org.junit.jupiter.api.Test;
28  
29  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
30  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
31  
32  public class NumericalPrefixesInfixesSuffixesCharacterCaseCheckTest
33          extends AbstractModuleTestSupport {
34  
35      @Override
36      public String getPackageLocation() {
37          return
38              "com/puppycrawl/tools/checkstyle/checks/numericalprefixesinfixessuffixescharactercase";
39      }
40  
41      @Test
42      public void testGetRequiredTokens() {
43          final NumericalPrefixesInfixesSuffixesCharacterCaseCheck check =
44              new NumericalPrefixesInfixesSuffixesCharacterCaseCheck();
45          final int[] expectedTokens = {TokenTypes.NUM_LONG, TokenTypes.NUM_INT,
46              TokenTypes.NUM_FLOAT, TokenTypes.NUM_DOUBLE,
47          };
48          assertWithMessage("Default required tokens are valid")
49              .that(check.getRequiredTokens())
50              .isEqualTo(expectedTokens);
51      }
52  
53      @Test
54      public void testAcceptableTokens() {
55          final int[] expected = {TokenTypes.NUM_LONG, TokenTypes.NUM_INT,
56              TokenTypes.NUM_FLOAT, TokenTypes.NUM_DOUBLE,
57          };
58          final NumericalPrefixesInfixesSuffixesCharacterCaseCheck check =
59              new NumericalPrefixesInfixesSuffixesCharacterCaseCheck();
60          final int[] actual = check.getAcceptableTokens();
61          assertWithMessage("Invalid size of tokens")
62                  .that(actual.length)
63                  .isEqualTo(4);
64          assertWithMessage("Default acceptable tokens are invalid")
65                  .that(actual)
66                  .isEqualTo(expected);
67      }
68  
69      @Test
70      public void testCheck()
71              throws Exception {
72          final String[] expected = {
73              "11:16: " + getCheckMessage(MSG_PREFIX),
74              "14:16: " + getCheckMessage(MSG_PREFIX),
75              "17:18: " + getCheckMessage(MSG_INFIX),
76              "20:22: " + getCheckMessage(MSG_INFIX),
77              "23:18: " + getCheckMessage(MSG_SUFFIX),
78              "26:19: " + getCheckMessage(MSG_SUFFIX),
79              "29:18: " + getCheckMessage(MSG_INFIX),
80              "32:19: " + getCheckMessage(MSG_INFIX),
81              "33:19: " + getCheckMessage(MSG_SUFFIX),
82          };
83          verifyWithInlineConfigParser(
84                  getPath("InputNumericalPrefixesInfixesSuffixesCharacterCaseCheck.java"), expected
85          );
86      }
87  }