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.JavadocParagraphCheck.MSG_LINE_BEFORE;
23  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_MISPLACED_TAG;
24  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_REDUNDANT_PARAGRAPH;
25  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_TAG_AFTER;
26  import static org.junit.Assert.assertArrayEquals;
27  
28  import org.junit.Test;
29  
30  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
31  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
32  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
33  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
34  
35  public class JavadocParagraphCheckTest extends AbstractModuleTestSupport {
36      @Override
37      protected String getPackageLocation() {
38          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocparagraph";
39      }
40  
41      @Test
42      public void testGetRequiredTokens() {
43          final JavadocParagraphCheck checkObj = new JavadocParagraphCheck();
44          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
45          assertArrayEquals("Default required tokens are invalid",
46              expected, checkObj.getRequiredTokens());
47      }
48  
49      @Test
50      public void testCorrect() throws Exception {
51          final DefaultConfiguration checkConfig = createModuleConfig(JavadocParagraphCheck.class);
52          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
53  
54          verify(checkConfig, getPath("InputJavadocParagraphCorrect.java"), expected);
55      }
56  
57      @Test
58      public void testIncorrect() throws Exception {
59          final DefaultConfiguration checkConfig = createModuleConfig(JavadocParagraphCheck.class);
60          final String[] expected = {
61              "7: " + getCheckMessage(MSG_MISPLACED_TAG),
62              "7: " + getCheckMessage(MSG_LINE_BEFORE),
63              "8: " + getCheckMessage(MSG_MISPLACED_TAG),
64              "8: " + getCheckMessage(MSG_LINE_BEFORE),
65              "14: " + getCheckMessage(MSG_MISPLACED_TAG),
66              "14: " + getCheckMessage(MSG_LINE_BEFORE),
67              "16: " + getCheckMessage(MSG_MISPLACED_TAG),
68              "23: " + getCheckMessage(MSG_LINE_BEFORE),
69              "25: " + getCheckMessage(MSG_MISPLACED_TAG),
70              "32: " + getCheckMessage(MSG_MISPLACED_TAG),
71              "32: " + getCheckMessage(MSG_LINE_BEFORE),
72              "32: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
73              "33: " + getCheckMessage(MSG_MISPLACED_TAG),
74              "33: " + getCheckMessage(MSG_LINE_BEFORE),
75              "34: " + getCheckMessage(MSG_MISPLACED_TAG),
76              "34: " + getCheckMessage(MSG_LINE_BEFORE),
77              "35: " + getCheckMessage(MSG_MISPLACED_TAG),
78              "35: " + getCheckMessage(MSG_LINE_BEFORE),
79              "39: " + getCheckMessage(MSG_MISPLACED_TAG),
80              "39: " + getCheckMessage(MSG_LINE_BEFORE),
81              "45: " + getCheckMessage(MSG_MISPLACED_TAG),
82              "45: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
83              "48: " + getCheckMessage(MSG_MISPLACED_TAG),
84              "50: " + getCheckMessage(MSG_MISPLACED_TAG),
85              "50: " + getCheckMessage(MSG_LINE_BEFORE),
86              "51: " + getCheckMessage(MSG_MISPLACED_TAG),
87              "51: " + getCheckMessage(MSG_LINE_BEFORE),
88              "61: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
89              "62: " + getCheckMessage(MSG_TAG_AFTER),
90              "70: " + getCheckMessage(MSG_MISPLACED_TAG),
91              "70: " + getCheckMessage(MSG_LINE_BEFORE),
92              "72: " + getCheckMessage(MSG_MISPLACED_TAG),
93              "75: " + getCheckMessage(MSG_MISPLACED_TAG),
94              "75: " + getCheckMessage(MSG_LINE_BEFORE),
95              "81: " + getCheckMessage(MSG_TAG_AFTER),
96              "82: " + getCheckMessage(MSG_TAG_AFTER),
97          };
98          verify(checkConfig, getPath("InputJavadocParagraphIncorrect.java"), expected);
99      }
100 
101     @Test
102     public void testAllowNewlineParagraph() throws Exception {
103         final DefaultConfiguration checkConfig = createModuleConfig(JavadocParagraphCheck.class);
104         checkConfig.addAttribute("allowNewlineParagraph", "false");
105         final String[] expected = {
106             "7: " + getCheckMessage(MSG_LINE_BEFORE),
107             "8: " + getCheckMessage(MSG_LINE_BEFORE),
108             "14: " + getCheckMessage(MSG_LINE_BEFORE),
109             "23: " + getCheckMessage(MSG_LINE_BEFORE),
110             "32: " + getCheckMessage(MSG_LINE_BEFORE),
111             "32: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
112             "33: " + getCheckMessage(MSG_LINE_BEFORE),
113             "34: " + getCheckMessage(MSG_LINE_BEFORE),
114             "35: " + getCheckMessage(MSG_LINE_BEFORE),
115             "39: " + getCheckMessage(MSG_LINE_BEFORE),
116             "45: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
117             "50: " + getCheckMessage(MSG_LINE_BEFORE),
118             "51: " + getCheckMessage(MSG_LINE_BEFORE),
119             "61: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
120             "62: " + getCheckMessage(MSG_TAG_AFTER),
121             "70: " + getCheckMessage(MSG_LINE_BEFORE),
122             "75: " + getCheckMessage(MSG_LINE_BEFORE),
123             "81: " + getCheckMessage(MSG_TAG_AFTER),
124             "82: " + getCheckMessage(MSG_TAG_AFTER),
125         };
126         verify(checkConfig, getPath("InputJavadocParagraphIncorrect.java"), expected);
127     }
128 }