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.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace;
21  
22  import org.junit.Test;
23  
24  import com.google.checkstyle.test.base.AbstractModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.api.Configuration;
26  import com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck;
27  
28  public class ParenPadTest extends AbstractModuleTestSupport {
29  
30      @Override
31      protected String getPackageLocation() {
32          return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace";
33      }
34  
35      @Test
36      public void testMethodParen() throws Exception {
37  
38          final Class<ParenPadCheck> clazz = ParenPadCheck.class;
39          final String messageKeyPreceded = "ws.preceded";
40          final String messageKeyFollowed = "ws.followed";
41  
42          final String[] expected = {
43              "44:27: " + getCheckMessage(clazz, messageKeyFollowed, "("),
44              "44:27: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
45              "45:18: " + getCheckMessage(clazz, messageKeyFollowed, "("),
46              "48:27: " + getCheckMessage(clazz, messageKeyFollowed, "("),
47              "49:19: " + getCheckMessage(clazz, messageKeyFollowed, "("),
48              "49:19: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
49              "52:27: " + getCheckMessage(clazz, messageKeyFollowed, "("),
50              "53:21: " + getCheckMessage(clazz, messageKeyFollowed, "("),
51              "54:18: " + getCheckMessage(clazz, messageKeyFollowed, "("),
52              "54:52: " + getCheckMessage(clazz, messageKeyFollowed, "("),
53              "54:52: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
54              "57:26: " + getCheckMessage(clazz, messageKeyFollowed, "("),
55              "58:22: " + getCheckMessage(clazz, messageKeyFollowed, "("),
56              "59:24: " + getCheckMessage(clazz, messageKeyFollowed, "("),
57              "60:26: " + getCheckMessage(clazz, messageKeyFollowed, "("),
58              "60:51: " + getCheckMessage(clazz, messageKeyFollowed, "("),
59              "60:57: " + getCheckMessage(clazz, messageKeyFollowed, "("),
60              "61:29: " + getCheckMessage(clazz, messageKeyFollowed, "("),
61              "62:43: " + getCheckMessage(clazz, messageKeyFollowed, "("),
62              "63:41: " + getCheckMessage(clazz, messageKeyFollowed, "("),
63              "65:43: " + getCheckMessage(clazz, messageKeyFollowed, "("),
64              "78:28: " + getCheckMessage(clazz, messageKeyFollowed, "("),
65              "78:28: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
66              "79:19: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
67              "82:33: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
68              "83:19: " + getCheckMessage(clazz, messageKeyFollowed, "("),
69              "83:19: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
70              "86:29: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
71              "87:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
72              "88:51: " + getCheckMessage(clazz, messageKeyFollowed, "("),
73              "88:51: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
74              "88:53: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
75              "90:38: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
76              "91:32: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
77              "92:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
78              "93:30: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
79              "94:60: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
80              "94:62: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
81              "94:69: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
82              "95:34: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
83              "96:47: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
84              "97:42: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
85              "99:44: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
86              "112:17: " + getCheckMessage(clazz, messageKeyFollowed, "("),
87              "113:23: " + getCheckMessage(clazz, messageKeyFollowed, "("),
88              "113:25: " + getCheckMessage(clazz, messageKeyFollowed, "("),
89              "113:31: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
90              "114:26: " + getCheckMessage(clazz, messageKeyFollowed, "("),
91              "114:28: " + getCheckMessage(clazz, messageKeyFollowed, "("),
92              "114:34: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
93              "114:50: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
94              "115:26: " + getCheckMessage(clazz, messageKeyFollowed, "("),
95              "115:28: " + getCheckMessage(clazz, messageKeyFollowed, "("),
96              "115:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
97              "115:53: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
98              "115:55: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
99              "119:17: " + getCheckMessage(clazz, messageKeyFollowed, "("),
100             "119:22: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
101             "123:30: " + getCheckMessage(clazz, messageKeyFollowed, "("),
102             "123:44: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
103             "126:22: " + getCheckMessage(clazz, messageKeyFollowed, "("),
104             "126:22: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
105             "130:19: " + getCheckMessage(clazz, messageKeyFollowed, "("),
106             "130:19: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
107             "139:10: " + getCheckMessage(clazz, messageKeyFollowed, "("),
108             "139:20: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
109             "145:33: " + getCheckMessage(clazz, messageKeyFollowed, "("),
110             "145:46: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
111             "153:34: " + getCheckMessage(clazz, messageKeyFollowed, "("),
112             "154:48: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
113             "155:36: " + getCheckMessage(clazz, messageKeyFollowed, "("),
114             "155:46: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
115             "159:26: " + getCheckMessage(clazz, messageKeyFollowed, "("),
116             "159:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
117             "160:13: " + getCheckMessage(clazz, messageKeyFollowed, "("),
118             "160:29: " + getCheckMessage(clazz, messageKeyFollowed, "("),
119             "160:48: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
120             "160:50: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
121             "163:32: " + getCheckMessage(clazz, messageKeyFollowed, "("),
122             "163:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
123             "163:48: " + getCheckMessage(clazz, messageKeyFollowed, "("),
124             "163:60: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
125             "166:39: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
126             "167:25: " + getCheckMessage(clazz, messageKeyFollowed, "("),
127             "167:50: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
128             "173:38: " + getCheckMessage(clazz, messageKeyFollowed, "("),
129             "174:48: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
130             "175:21: " + getCheckMessage(clazz, messageKeyFollowed, "("),
131             "175:48: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
132             "185:17: " + getCheckMessage(clazz, messageKeyFollowed, "("),
133             "185:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
134             "186:20: " + getCheckMessage(clazz, messageKeyFollowed, "("),
135             "186:38: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
136             "190:30: " + getCheckMessage(clazz, messageKeyFollowed, "("),
137             "190:44: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
138             "191:13: " + getCheckMessage(clazz, messageKeyFollowed, "("),
139             "191:38: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
140             "192:23: " + getCheckMessage(clazz, messageKeyFollowed, "("),
141             "192:39: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
142             "200:81: " + getCheckMessage(clazz, messageKeyFollowed, "("),
143             "200:83: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
144             "201:21: " + getCheckMessage(clazz, messageKeyFollowed, "("),
145             "202:23: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
146             "203:21: " + getCheckMessage(clazz, messageKeyFollowed, "("),
147             "203:24: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
148             "206:14: " + getCheckMessage(clazz, messageKeyFollowed, "("),
149             "206:22: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
150             "206:32: " + getCheckMessage(clazz, messageKeyFollowed, "("),
151             "207:18: " + getCheckMessage(clazz, messageKeyFollowed, "("),
152             "207:46: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
153             "210:37: " + getCheckMessage(clazz, messageKeyFollowed, "("),
154             "210:74: " + getCheckMessage(clazz, messageKeyFollowed, "("),
155             "210:80: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
156             "210:82: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
157             "211:37: " + getCheckMessage(clazz, messageKeyFollowed, "("),
158             "212:49: " + getCheckMessage(clazz, messageKeyFollowed, "("),
159             "212:51: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
160             "212:53: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
161             "220:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
162             "221:60: " + getCheckMessage(clazz, messageKeyPreceded, ")"),
163         };
164         final Configuration checkConfig = getModuleConfig("ParenPad");
165         final String filePath = getPath("InputParenPad.java");
166 
167         final Integer[] warnList = getLinesWithWarn(filePath);
168         verify(checkConfig, filePath, expected, warnList);
169     }
170 }