1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
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.NonEmptyAtclauseDescriptionCheck.MSG_KEY;
24  
25  import java.nio.charset.CodingErrorAction;
26  
27  import org.junit.jupiter.api.Test;
28  
29  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
30  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
31  import com.puppycrawl.tools.checkstyle.TreeWalker;
32  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
33  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
34  import de.thetaphi.forbiddenapis.SuppressForbidden;
35  
36  public class NonEmptyAtclauseDescriptionCheckTest
37          extends AbstractModuleTestSupport {
38  
39      @Override
40      protected String getPackageLocation() {
41          return "com/puppycrawl/tools/checkstyle/checks/javadoc/nonemptyatclausedescription";
42      }
43  
44      @Test
45      public void testGetAcceptableTokens() {
46          final NonEmptyAtclauseDescriptionCheck checkObj =
47              new NonEmptyAtclauseDescriptionCheck();
48          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
49          assertWithMessage("Default acceptable tokens are invalid")
50                  .that(checkObj.getAcceptableTokens())
51                  .isEqualTo(expected);
52      }
53  
54      @Test
55      public void testGetRequiredTokens() {
56          final NonEmptyAtclauseDescriptionCheck checkObj =
57              new NonEmptyAtclauseDescriptionCheck();
58          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
59          assertWithMessage("Default required tokens are invalid")
60                  .that(checkObj.getRequiredTokens())
61                  .isEqualTo(expected);
62      }
63  
64      @Test
65      public void testCheckOne() throws Exception {
66          final String[] expected = {
67              
68              "37: " + getCheckMessage(MSG_KEY),
69              
70              "38: " + getCheckMessage(MSG_KEY),
71              
72              "39: " + getCheckMessage(MSG_KEY),
73              
74              "50: " + getCheckMessage(MSG_KEY),
75              
76              "51: " + getCheckMessage(MSG_KEY),
77              
78              "52: " + getCheckMessage(MSG_KEY),
79              "92: " + getCheckMessage(MSG_KEY),
80              "93: " + getCheckMessage(MSG_KEY),
81              "94: " + getCheckMessage(MSG_KEY),
82              "95: " + getCheckMessage(MSG_KEY),
83              "96: " + getCheckMessage(MSG_KEY),
84              "97: " + getCheckMessage(MSG_KEY),
85          };
86          verifyWithInlineConfigParser(getPath("InputNonEmptyAtclauseDescriptionOne.java"), expected);
87      }
88  
89      @Test
90      public void testCheckTwo() throws Exception {
91          final String[] expected = {
92              "16: " + getCheckMessage(MSG_KEY),
93              "17: " + getCheckMessage(MSG_KEY),
94              "18: " + getCheckMessage(MSG_KEY),
95              "19: " + getCheckMessage(MSG_KEY),
96              "20: " + getCheckMessage(MSG_KEY),
97              "51: " + getCheckMessage(MSG_KEY),
98              "60: " + getCheckMessage(MSG_KEY),
99              "75: " + getCheckMessage(MSG_KEY),
100             "77: " + getCheckMessage(MSG_KEY),
101             "88: " + getCheckMessage(MSG_KEY),
102             "97: " + getCheckMessage(MSG_KEY),
103         };
104         verifyWithInlineConfigParser(getPath("InputNonEmptyAtclauseDescriptionTwo.java"), expected);
105     }
106 
107     
108 
109 
110 
111 
112 
113 
114 
115     @SuppressForbidden
116     @Test
117     public void testDecoderOnMalformedInput() throws Exception {
118         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
119         final DefaultConfiguration checkConfig =
120                 createModuleConfig(NonEmptyAtclauseDescriptionCheck.class);
121 
122         final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
123         treeWalkerConfig.addChild(checkConfig);
124 
125         final DefaultConfiguration checkerConfig = createRootConfig(treeWalkerConfig);
126         checkerConfig.addChild(treeWalkerConfig);
127         checkerConfig.addProperty("charset", "US-ASCII");
128 
129         verify(checkerConfig,
130                 getPath("InputNonEmptyAtclauseDescriptionDifferentCharset.java"), expected);
131     }
132 
133     @Test
134     public void testExample3() throws Exception {
135         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
136         verifyWithInlineConfigParser(
137                 getPath("InputNonEmptyAtclauseDescriptionThree.java"), expected);
138     }
139 }