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.javadoc;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocEndCommentDelimiterCheck.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  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class JavadocEndCommentDelimiterCheckTest extends AbstractModuleTestSupport {
32  
33      @Override
34      public String getPackageLocation() {
35          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocendcommentdelimiter";
36      }
37  
38      @Test
39      public void testGetAcceptableTokens() {
40          final int[] expected = {
41              TokenTypes.BLOCK_COMMENT_BEGIN,
42          };
43          final JavadocEndCommentDelimiterCheck check = new JavadocEndCommentDelimiterCheck();
44          final int[] actual = check.getAcceptableTokens();
45  
46          assertWithMessage("Acceptable tokens differ from expected")
47              .that(actual)
48              .isEqualTo(expected);
49      }
50  
51      @Test
52      public void testGetRequiredTokens() {
53          final int[] expected = {
54              TokenTypes.BLOCK_COMMENT_BEGIN,
55          };
56          final JavadocEndCommentDelimiterCheck check = new JavadocEndCommentDelimiterCheck();
57          final int[] actual = check.getRequiredTokens();
58  
59          assertWithMessage("Required tokens differ from expected")
60              .that(actual)
61              .isEqualTo(expected);
62      }
63  
64      @Test
65      public void testCorrect() throws Exception {
66          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
67  
68          verifyWithInlineConfigParser(
69                  getPath("InputJavadocEndCommentDelimiterCorrect.java"), expected);
70      }
71  
72      @Test
73      public void testIncorrect() throws Exception {
74          final String[] expected = {
75              "14:7: " + getCheckMessage(MSG_KEY),
76              "20:8: " + getCheckMessage(MSG_KEY),
77              "26:9: " + getCheckMessage(MSG_KEY),
78              "30:18: " + getCheckMessage(MSG_KEY),
79              "34:19: " + getCheckMessage(MSG_KEY),
80              "38:20: " + getCheckMessage(MSG_KEY),
81              "44:7: " + getCheckMessage(MSG_KEY),
82              "50:7: " + getCheckMessage(MSG_KEY),
83          };
84  
85          verifyWithInlineConfigParser(
86                  getPath("InputJavadocEndCommentDelimiterIncorrect.java"), expected);
87      }
88  
89  }