View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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.puppycrawl.tools.checkstyle.checks.javadoc.SingleLineJavadocCheck.MSG_KEY;
23  import static org.junit.Assert.assertArrayEquals;
24  
25  import org.junit.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
30  
31  public class SingleLineJavadocCheckTest extends AbstractModuleTestSupport {
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/javadoc/singlelinejavadoc";
35      }
36  
37      @Test
38      public void testAcceptableTokens() {
39          final SingleLineJavadocCheck checkObj = new SingleLineJavadocCheck();
40          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
41          assertArrayEquals("Default acceptable tokens are invalid",
42              expected, checkObj.getAcceptableTokens());
43      }
44  
45      @Test
46      public void testGetRequiredTokens() {
47          final SingleLineJavadocCheck checkObj = new SingleLineJavadocCheck();
48          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
49          assertArrayEquals("Default required tokens are invalid",
50              expected, checkObj.getRequiredTokens());
51      }
52  
53      @Test
54      public void simpleTest() throws Exception {
55          final DefaultConfiguration checkConfig =
56                  createModuleConfig(SingleLineJavadocCheck.class);
57          final String[] expected = {
58              "12: " + getCheckMessage(MSG_KEY),
59              "28: " + getCheckMessage(MSG_KEY),
60              "40: " + getCheckMessage(MSG_KEY),
61              "43: " + getCheckMessage(MSG_KEY),
62              "49: " + getCheckMessage(MSG_KEY),
63          };
64          verify(checkConfig, getPath("InputSingleLineJavadoc.java"), expected);
65      }
66  
67      @Test
68      public void testIgnoredTags() throws Exception {
69          final DefaultConfiguration checkConfig =
70                  createModuleConfig(SingleLineJavadocCheck.class);
71          checkConfig.addAttribute("ignoredTags", "@inheritDoc, @throws,  "
72              + "@ignoredCustomTag");
73          checkConfig.addAttribute("ignoreInlineTags", "false");
74  
75          final String[] expected = {
76              "4: " + getCheckMessage(MSG_KEY),
77              "34: " + getCheckMessage(MSG_KEY),
78              "37: " + getCheckMessage(MSG_KEY),
79              "40: " + getCheckMessage(MSG_KEY),
80              "46: " + getCheckMessage(MSG_KEY),
81              "49: " + getCheckMessage(MSG_KEY),
82          };
83          verify(checkConfig, getPath("InputSingleLineJavadoc.java"), expected);
84      }
85  }