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