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