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.AtclauseOrderCheck.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  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
31  
32  public class AtclauseOrderCheckTest extends AbstractModuleTestSupport {
33      @Override
34      protected String getPackageLocation() {
35          return "com/puppycrawl/tools/checkstyle/checks/javadoc/atclauseorder";
36      }
37  
38      @Test
39      public void testGetAcceptableTokens() {
40          final AtclauseOrderCheck checkObj = new AtclauseOrderCheck();
41          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
42          assertArrayEquals("Default acceptable tokens are invalid",
43              expected, checkObj.getAcceptableTokens());
44      }
45  
46      @Test
47      public void testGetRequiredTokens() {
48          final AtclauseOrderCheck checkObj = new AtclauseOrderCheck();
49          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
50          assertArrayEquals("Default required tokens are invalid",
51              expected, checkObj.getRequiredTokens());
52      }
53  
54      @Test
55      public void testCorrect() throws Exception {
56          final DefaultConfiguration checkConfig = createModuleConfig(AtclauseOrderCheck.class);
57          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
58  
59          verify(checkConfig, getPath("InputAtclauseOrderCorrect.java"), expected);
60      }
61  
62      @Test
63      public void testIncorrect() throws Exception {
64          final String tagOrder = "[@author, @version, @param, @return, @throws, @exception, @see,"
65                  + " @since, @serial, @serialField, @serialData, @deprecated]";
66          final DefaultConfiguration checkConfig = createModuleConfig(AtclauseOrderCheck.class);
67          final String[] expected = {
68              "9: " + getCheckMessage(MSG_KEY, tagOrder),
69              "11: " + getCheckMessage(MSG_KEY, tagOrder),
70              "12: " + getCheckMessage(MSG_KEY, tagOrder),
71              "40: " + getCheckMessage(MSG_KEY, tagOrder),
72              "50: " + getCheckMessage(MSG_KEY, tagOrder),
73              "51: " + getCheckMessage(MSG_KEY, tagOrder),
74              "52: " + getCheckMessage(MSG_KEY, tagOrder),
75              "62: " + getCheckMessage(MSG_KEY, tagOrder),
76              "69: " + getCheckMessage(MSG_KEY, tagOrder),
77              "86: " + getCheckMessage(MSG_KEY, tagOrder),
78              "87: " + getCheckMessage(MSG_KEY, tagOrder),
79              "99: " + getCheckMessage(MSG_KEY, tagOrder),
80              "100: " + getCheckMessage(MSG_KEY, tagOrder),
81              "101: " + getCheckMessage(MSG_KEY, tagOrder),
82              "115: " + getCheckMessage(MSG_KEY, tagOrder),
83              "123: " + getCheckMessage(MSG_KEY, tagOrder),
84              "124: " + getCheckMessage(MSG_KEY, tagOrder),
85              "134: " + getCheckMessage(MSG_KEY, tagOrder),
86              "135: " + getCheckMessage(MSG_KEY, tagOrder),
87              "145: " + getCheckMessage(MSG_KEY, tagOrder),
88              "146: " + getCheckMessage(MSG_KEY, tagOrder),
89              "153: " + getCheckMessage(MSG_KEY, tagOrder),
90              "161: " + getCheckMessage(MSG_KEY, tagOrder),
91              "172: " + getCheckMessage(MSG_KEY, tagOrder),
92              "183: " + getCheckMessage(MSG_KEY, tagOrder),
93              "185: " + getCheckMessage(MSG_KEY, tagOrder),
94              "199: " + getCheckMessage(MSG_KEY, tagOrder),
95              "202: " + getCheckMessage(MSG_KEY, tagOrder),
96              "213: " + getCheckMessage(MSG_KEY, tagOrder),
97              "223: " + getCheckMessage(MSG_KEY, tagOrder),
98              "230: " + getCheckMessage(MSG_KEY, tagOrder),
99              "237: " + getCheckMessage(MSG_KEY, tagOrder),
100             "247: " + getCheckMessage(MSG_KEY, tagOrder),
101             "248: " + getCheckMessage(MSG_KEY, tagOrder),
102             "259: " + getCheckMessage(MSG_KEY, tagOrder),
103             "261: " + getCheckMessage(MSG_KEY, tagOrder),
104             "275: " + getCheckMessage(MSG_KEY, tagOrder),
105             "277: " + getCheckMessage(MSG_KEY, tagOrder),
106             "278: " + getCheckMessage(MSG_KEY, tagOrder),
107             "288: " + getCheckMessage(MSG_KEY, tagOrder),
108         };
109         verify(checkConfig, getPath("InputAtclauseOrderIncorrect.java"), expected);
110     }
111 
112     @Test
113     public void testIncorrectCustom() throws Exception {
114 
115         final DefaultConfiguration checkConfig = createModuleConfig(AtclauseOrderCheck.class);
116         checkConfig.addAttribute("target", "CLASS_DEF");
117         checkConfig.addAttribute("tagOrder", " @since,  @version, @param,@return,@throws, "
118                 + "@exception,@deprecated, @see,@serial,   @serialField,  @serialData,@author");
119 
120         final String tagOrder = "[@since, @version, @param, @return, @throws, @exception,"
121                 + " @deprecated, @see, @serial, @serialField, @serialData, @author]";
122         final String[] expected = {
123             "113: " + getCheckMessage(MSG_KEY, tagOrder),
124         };
125         verify(checkConfig, getPath("InputAtclauseOrderIncorrect.java"), expected);
126     }
127 }