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.coding;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck.MSG_KEY;
23  
24  import org.junit.Test;
25  
26  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
27  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
28  
29  public class MagicNumberCheckTest
30      extends AbstractModuleTestSupport {
31      @Override
32      protected String getPackageLocation() {
33          return "com/puppycrawl/tools/checkstyle/checks/coding/magicnumber";
34      }
35  
36      @Test
37      public void testDefault()
38              throws Exception {
39          final DefaultConfiguration checkConfig =
40              createModuleConfig(MagicNumberCheck.class);
41          final String[] expected = {
42              "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
43              "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
44              "43:27: " + getCheckMessage(MSG_KEY, "3"),
45              "43:31: " + getCheckMessage(MSG_KEY, "4"),
46              "45:29: " + getCheckMessage(MSG_KEY, "3"),
47              "47:23: " + getCheckMessage(MSG_KEY, "3"),
48              "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
49              "50:22: " + getCheckMessage(MSG_KEY, "3"),
50              "50:29: " + getCheckMessage(MSG_KEY, "5"),
51              "50:37: " + getCheckMessage(MSG_KEY, "3"),
52              "54:26: " + getCheckMessage(MSG_KEY, "3"),
53              "55:39: " + getCheckMessage(MSG_KEY, "3"),
54              "60:25: " + getCheckMessage(MSG_KEY, "010"),
55              "61:25: " + getCheckMessage(MSG_KEY, "011"),
56              "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
57              "64:30: " + getCheckMessage(MSG_KEY, "011l"),
58              "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
59              "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
60              "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
61              "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
62              "85:28: " + getCheckMessage(MSG_KEY, "3"),
63              "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
64              "100:30: " + getCheckMessage(MSG_KEY, "+3"),
65              "101:29: " + getCheckMessage(MSG_KEY, "-2"),
66              "102:35: " + getCheckMessage(MSG_KEY, "+3.5"),
67              "103:36: " + getCheckMessage(MSG_KEY, "-2.5"),
68              "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
69              "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
70              "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
71              "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
72              "131:20: " + getCheckMessage(MSG_KEY, "378"),
73              "160:16: " + getCheckMessage(MSG_KEY, "31"),
74              "165:16: " + getCheckMessage(MSG_KEY, "42"),
75              "170:16: " + getCheckMessage(MSG_KEY, "13"),
76              "174:15: " + getCheckMessage(MSG_KEY, "21"),
77              "178:15: " + getCheckMessage(MSG_KEY, "37"),
78              "182:15: " + getCheckMessage(MSG_KEY, "101"),
79              "185:42: " + getCheckMessage(MSG_KEY, "42"),
80              "189:48: " + getCheckMessage(MSG_KEY, "43"),
81              "193:42: " + getCheckMessage(MSG_KEY, "-44"),
82              "197:48: " + getCheckMessage(MSG_KEY, "-45"),
83          };
84          verify(checkConfig, getPath("InputMagicNumber.java"), expected);
85      }
86  
87      @Test
88      public void testIgnoreSome()
89              throws Exception {
90          final DefaultConfiguration checkConfig =
91              createModuleConfig(MagicNumberCheck.class);
92          checkConfig.addAttribute("ignoreNumbers", "0, 1, 3.0, 8, 16, 3000");
93          checkConfig.addAttribute("ignoreAnnotation", "true");
94          final String[] expected = {
95              "22:25: " + getCheckMessage(MSG_KEY, "2"),
96              "28:35: " + getCheckMessage(MSG_KEY, "2"),
97              "30:24: " + getCheckMessage(MSG_KEY, "2"),
98              "32:29: " + getCheckMessage(MSG_KEY, "2.0"),
99              "34:29: " + getCheckMessage(MSG_KEY, "2"),
100             "36:17: " + getCheckMessage(MSG_KEY, "2"),
101             "38:19: " + getCheckMessage(MSG_KEY, "2.0"),
102             "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
103             "43:31: " + getCheckMessage(MSG_KEY, "4"),
104             "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
105             "50:29: " + getCheckMessage(MSG_KEY, "5"),
106             "61:25: " + getCheckMessage(MSG_KEY, "011"),
107             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
108             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
109             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
110             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
111             "101:29: " + getCheckMessage(MSG_KEY, "-2"),
112             "102:35: " + getCheckMessage(MSG_KEY, "+3.5"),
113             "103:36: " + getCheckMessage(MSG_KEY, "-2.5"),
114             "109:34: " + getCheckMessage(MSG_KEY, "0xffffffff"),
115             "110:36: " + getCheckMessage(MSG_KEY, "0xffffffffffffffffL"),
116             "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
117             "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
118             "113:36: " + getCheckMessage(MSG_KEY, "037777777777"),
119             "114:38: " + getCheckMessage(MSG_KEY, "01777777777777777777777L"),
120             "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
121             "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
122             "131:20: " + getCheckMessage(MSG_KEY, "378"),
123             "160:16: " + getCheckMessage(MSG_KEY, "31"),
124             "165:16: " + getCheckMessage(MSG_KEY, "42"),
125             "170:16: " + getCheckMessage(MSG_KEY, "13"),
126             "174:15: " + getCheckMessage(MSG_KEY, "21"),
127             "178:15: " + getCheckMessage(MSG_KEY, "37"),
128             "182:15: " + getCheckMessage(MSG_KEY, "101"),
129         };
130         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
131     }
132 
133     @Test
134     public void testIgnoreNone()
135             throws Exception {
136         final DefaultConfiguration checkConfig =
137             createModuleConfig(MagicNumberCheck.class);
138         checkConfig.addAttribute("ignoreNumbers", "");
139         checkConfig.addAttribute("ignoreAnnotation", "true");
140         final String[] expected = {
141             "21:24: " + getCheckMessage(MSG_KEY, "1"),
142             "22:25: " + getCheckMessage(MSG_KEY, "2"),
143             "23:26: " + getCheckMessage(MSG_KEY, "0L"),
144             "24:26: " + getCheckMessage(MSG_KEY, "0l"),
145             "25:30: " + getCheckMessage(MSG_KEY, "0D"),
146             "26:30: " + getCheckMessage(MSG_KEY, "0d"),
147             "28:35: " + getCheckMessage(MSG_KEY, "2"),
148             "30:20: " + getCheckMessage(MSG_KEY, "1"),
149             "30:24: " + getCheckMessage(MSG_KEY, "2"),
150             "31:21: " + getCheckMessage(MSG_KEY, "1"),
151             "32:23: " + getCheckMessage(MSG_KEY, "1.0"),
152             "32:29: " + getCheckMessage(MSG_KEY, "2.0"),
153             "34:22: " + getCheckMessage(MSG_KEY, "0"),
154             "34:29: " + getCheckMessage(MSG_KEY, "2"),
155             "36:13: " + getCheckMessage(MSG_KEY, "1"),
156             "36:17: " + getCheckMessage(MSG_KEY, "2"),
157             "38:13: " + getCheckMessage(MSG_KEY, "1.0"),
158             "38:19: " + getCheckMessage(MSG_KEY, "2.0"),
159             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
160             "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
161             "43:27: " + getCheckMessage(MSG_KEY, "3"),
162             "43:31: " + getCheckMessage(MSG_KEY, "4"),
163             "45:29: " + getCheckMessage(MSG_KEY, "3"),
164             "47:23: " + getCheckMessage(MSG_KEY, "3"),
165             "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
166             "50:22: " + getCheckMessage(MSG_KEY, "3"),
167             "50:29: " + getCheckMessage(MSG_KEY, "5"),
168             "50:37: " + getCheckMessage(MSG_KEY, "3"),
169             "54:26: " + getCheckMessage(MSG_KEY, "3"),
170             "55:39: " + getCheckMessage(MSG_KEY, "3"),
171             "59:25: " + getCheckMessage(MSG_KEY, "00"),
172             "60:25: " + getCheckMessage(MSG_KEY, "010"),
173             "61:25: " + getCheckMessage(MSG_KEY, "011"),
174             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
175             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
176             "67:23: " + getCheckMessage(MSG_KEY, "0x0"),
177             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
178             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
179             "70:28: " + getCheckMessage(MSG_KEY, "0x0L"),
180             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
181             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
182             "85:28: " + getCheckMessage(MSG_KEY, "3"),
183             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
184             "100:30: " + getCheckMessage(MSG_KEY, "+3"),
185             "101:29: " + getCheckMessage(MSG_KEY, "-2"),
186             "102:35: " + getCheckMessage(MSG_KEY, "+3.5"),
187             "103:36: " + getCheckMessage(MSG_KEY, "-2.5"),
188             "109:34: " + getCheckMessage(MSG_KEY, "0xffffffff"),
189             "110:36: " + getCheckMessage(MSG_KEY, "0xffffffffffffffffL"),
190             "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
191             "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
192             "113:36: " + getCheckMessage(MSG_KEY, "037777777777"),
193             "114:38: " + getCheckMessage(MSG_KEY, "01777777777777777777777L"),
194             "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
195             "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
196             "131:20: " + getCheckMessage(MSG_KEY, "378"),
197             "160:16: " + getCheckMessage(MSG_KEY, "31"),
198             "165:16: " + getCheckMessage(MSG_KEY, "42"),
199             "170:16: " + getCheckMessage(MSG_KEY, "13"),
200             "174:15: " + getCheckMessage(MSG_KEY, "21"),
201             "178:15: " + getCheckMessage(MSG_KEY, "37"),
202             "182:15: " + getCheckMessage(MSG_KEY, "101"),
203         };
204         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
205     }
206 
207     @Test
208     public void testIntegersOnly()
209             throws Exception {
210         final DefaultConfiguration checkConfig =
211             createModuleConfig(MagicNumberCheck.class);
212         checkConfig.addAttribute("tokens", "NUM_INT, NUM_LONG");
213         checkConfig.addAttribute("ignoreAnnotation", "true");
214         final String[] expected = {
215             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
216             "43:27: " + getCheckMessage(MSG_KEY, "3"),
217             "43:31: " + getCheckMessage(MSG_KEY, "4"),
218             "45:29: " + getCheckMessage(MSG_KEY, "3"),
219             "47:23: " + getCheckMessage(MSG_KEY, "3"),
220             "50:22: " + getCheckMessage(MSG_KEY, "3"),
221             "50:29: " + getCheckMessage(MSG_KEY, "5"),
222             "50:37: " + getCheckMessage(MSG_KEY, "3"),
223             "54:26: " + getCheckMessage(MSG_KEY, "3"),
224             "55:39: " + getCheckMessage(MSG_KEY, "3"),
225             "60:25: " + getCheckMessage(MSG_KEY, "010"),
226             "61:25: " + getCheckMessage(MSG_KEY, "011"),
227             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
228             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
229             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
230             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
231             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
232             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
233             "85:28: " + getCheckMessage(MSG_KEY, "3"),
234             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
235             "100:30: " + getCheckMessage(MSG_KEY, "+3"),
236             "101:29: " + getCheckMessage(MSG_KEY, "-2"),
237             "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
238             "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
239             "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
240             "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
241             "131:20: " + getCheckMessage(MSG_KEY, "378"),
242             "160:16: " + getCheckMessage(MSG_KEY, "31"),
243             "165:16: " + getCheckMessage(MSG_KEY, "42"),
244             "170:16: " + getCheckMessage(MSG_KEY, "13"),
245             "174:15: " + getCheckMessage(MSG_KEY, "21"),
246             "178:15: " + getCheckMessage(MSG_KEY, "37"),
247             "182:15: " + getCheckMessage(MSG_KEY, "101"),
248         };
249         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
250     }
251 
252     @Test
253     public void testIgnoreNegativeOctalHex() throws Exception {
254         final DefaultConfiguration checkConfig =
255             createModuleConfig(MagicNumberCheck.class);
256         checkConfig.addAttribute("ignoreNumbers",
257             "-9223372036854775808, -2147483648, -1, 0, 1, 2, -2");
258         checkConfig.addAttribute("tokens", "NUM_INT, NUM_LONG");
259         checkConfig.addAttribute("ignoreAnnotation", "true");
260         final String[] expected = {
261             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
262             "43:27: " + getCheckMessage(MSG_KEY, "3"),
263             "43:31: " + getCheckMessage(MSG_KEY, "4"),
264             "45:29: " + getCheckMessage(MSG_KEY, "3"),
265             "47:23: " + getCheckMessage(MSG_KEY, "3"),
266             "50:22: " + getCheckMessage(MSG_KEY, "3"),
267             "50:29: " + getCheckMessage(MSG_KEY, "5"),
268             "50:37: " + getCheckMessage(MSG_KEY, "3"),
269             "54:26: " + getCheckMessage(MSG_KEY, "3"),
270             "55:39: " + getCheckMessage(MSG_KEY, "3"),
271             "60:25: " + getCheckMessage(MSG_KEY, "010"),
272             "61:25: " + getCheckMessage(MSG_KEY, "011"),
273             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
274             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
275             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
276             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
277             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
278             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
279             "85:28: " + getCheckMessage(MSG_KEY, "3"),
280             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
281             "100:30: " + getCheckMessage(MSG_KEY, "+3"),
282             "131:20: " + getCheckMessage(MSG_KEY, "378"),
283             "160:16: " + getCheckMessage(MSG_KEY, "31"),
284             "165:16: " + getCheckMessage(MSG_KEY, "42"),
285             "170:16: " + getCheckMessage(MSG_KEY, "13"),
286             "174:15: " + getCheckMessage(MSG_KEY, "21"),
287             "178:15: " + getCheckMessage(MSG_KEY, "37"),
288             "182:15: " + getCheckMessage(MSG_KEY, "101"),
289         };
290         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
291     }
292 
293     @Test
294     public void testIgnoreHashCodeMethod() throws Exception {
295         final DefaultConfiguration checkConfig =
296             createModuleConfig(MagicNumberCheck.class);
297         checkConfig.addAttribute("ignoreHashCodeMethod", "true");
298         checkConfig.addAttribute("ignoreAnnotation", "true");
299         final String[] expected = {
300             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
301             "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
302             "43:27: " + getCheckMessage(MSG_KEY, "3"),
303             "43:31: " + getCheckMessage(MSG_KEY, "4"),
304             "45:29: " + getCheckMessage(MSG_KEY, "3"),
305             "47:23: " + getCheckMessage(MSG_KEY, "3"),
306             "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
307             "50:22: " + getCheckMessage(MSG_KEY, "3"),
308             "50:29: " + getCheckMessage(MSG_KEY, "5"),
309             "50:37: " + getCheckMessage(MSG_KEY, "3"),
310             "54:26: " + getCheckMessage(MSG_KEY, "3"),
311             "55:39: " + getCheckMessage(MSG_KEY, "3"),
312             "60:25: " + getCheckMessage(MSG_KEY, "010"),
313             "61:25: " + getCheckMessage(MSG_KEY, "011"),
314             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
315             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
316             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
317             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
318             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
319             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
320             "85:28: " + getCheckMessage(MSG_KEY, "3"),
321             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
322             "100:30: " + getCheckMessage(MSG_KEY, "+3"),
323             "101:29: " + getCheckMessage(MSG_KEY, "-2"),
324             "102:35: " + getCheckMessage(MSG_KEY, "+3.5"),
325             "103:36: " + getCheckMessage(MSG_KEY, "-2.5"),
326             "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
327             "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
328             "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
329             "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
330             "131:20: " + getCheckMessage(MSG_KEY, "378"),
331             "165:16: " + getCheckMessage(MSG_KEY, "42"),
332             "170:16: " + getCheckMessage(MSG_KEY, "13"),
333             "174:15: " + getCheckMessage(MSG_KEY, "21"),
334             "178:15: " + getCheckMessage(MSG_KEY, "37"),
335             "182:15: " + getCheckMessage(MSG_KEY, "101"),
336         };
337         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
338     }
339 
340     @Test
341     public void testIgnoreFieldDeclaration()
342             throws Exception {
343         final DefaultConfiguration checkConfig =
344                 createModuleConfig(MagicNumberCheck.class);
345         checkConfig.addAttribute("ignoreFieldDeclaration", "true");
346         final String[] expected = {
347             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
348             "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
349             "43:27: " + getCheckMessage(MSG_KEY, "3"),
350             "43:31: " + getCheckMessage(MSG_KEY, "4"),
351             "45:29: " + getCheckMessage(MSG_KEY, "3"),
352             "47:23: " + getCheckMessage(MSG_KEY, "3"),
353             "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
354             "50:22: " + getCheckMessage(MSG_KEY, "3"),
355             "50:29: " + getCheckMessage(MSG_KEY, "5"),
356             "50:37: " + getCheckMessage(MSG_KEY, "3"),
357             "54:26: " + getCheckMessage(MSG_KEY, "3"),
358             "55:39: " + getCheckMessage(MSG_KEY, "3"),
359             "60:25: " + getCheckMessage(MSG_KEY, "010"),
360             "61:25: " + getCheckMessage(MSG_KEY, "011"),
361             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
362             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
363             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
364             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
365             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
366             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
367             "131:20: " + getCheckMessage(MSG_KEY, "378"),
368             "160:16: " + getCheckMessage(MSG_KEY, "31"),
369             "165:16: " + getCheckMessage(MSG_KEY, "42"),
370             "170:16: " + getCheckMessage(MSG_KEY, "13"),
371             "174:15: " + getCheckMessage(MSG_KEY, "21"),
372             "178:15: " + getCheckMessage(MSG_KEY, "37"),
373             "182:15: " + getCheckMessage(MSG_KEY, "101"),
374             "185:42: " + getCheckMessage(MSG_KEY, "42"),
375             "189:48: " + getCheckMessage(MSG_KEY, "43"),
376             "193:42: " + getCheckMessage(MSG_KEY, "-44"),
377             "197:48: " + getCheckMessage(MSG_KEY, "-45"),
378         };
379         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
380     }
381 
382     @Test
383     public void testWaiverParentToken()
384             throws Exception {
385         final DefaultConfiguration checkConfig =
386                 createModuleConfig(MagicNumberCheck.class);
387         checkConfig.addAttribute("constantWaiverParentToken", "ASSIGN, ARRAY_INIT,"
388                 + " EXPR, UNARY_PLUS, UNARY_MINUS, TYPECAST, ELIST, STAR, DIV, PLUS, MINUS");
389         final String[] expected = {
390             "41:26: " + getCheckMessage(MSG_KEY, "3_000"),
391             "42:32: " + getCheckMessage(MSG_KEY, "1.5_0"),
392             "43:27: " + getCheckMessage(MSG_KEY, "3"),
393             "43:31: " + getCheckMessage(MSG_KEY, "4"),
394             "45:29: " + getCheckMessage(MSG_KEY, "3"),
395             "47:23: " + getCheckMessage(MSG_KEY, "3"),
396             "48:26: " + getCheckMessage(MSG_KEY, "1.5"),
397             "50:22: " + getCheckMessage(MSG_KEY, "3"),
398             "50:29: " + getCheckMessage(MSG_KEY, "5"),
399             "50:37: " + getCheckMessage(MSG_KEY, "3"),
400             "54:26: " + getCheckMessage(MSG_KEY, "3"),
401             "55:39: " + getCheckMessage(MSG_KEY, "3"),
402             "60:25: " + getCheckMessage(MSG_KEY, "010"),
403             "61:25: " + getCheckMessage(MSG_KEY, "011"),
404             "63:30: " + getCheckMessage(MSG_KEY, "0_10L"),
405             "64:30: " + getCheckMessage(MSG_KEY, "011l"),
406             "68:24: " + getCheckMessage(MSG_KEY, "0x10"),
407             "69:24: " + getCheckMessage(MSG_KEY, "0X011"),
408             "71:29: " + getCheckMessage(MSG_KEY, "0x10L"),
409             "72:29: " + getCheckMessage(MSG_KEY, "0X11l"),
410             "85:28: " + getCheckMessage(MSG_KEY, "3"),
411             "92:14: " + getCheckMessage(MSG_KEY, "0xffffffffL"),
412             "100:30: " + getCheckMessage(MSG_KEY, "+3"),
413             "101:29: " + getCheckMessage(MSG_KEY, "-2"),
414             "102:35: " + getCheckMessage(MSG_KEY, "+3.5"),
415             "103:36: " + getCheckMessage(MSG_KEY, "-2.5"),
416             "111:35: " + getCheckMessage(MSG_KEY, "0x80000000"),
417             "112:36: " + getCheckMessage(MSG_KEY, "0x8000000000000000L"),
418             "115:37: " + getCheckMessage(MSG_KEY, "020000000000"),
419             "116:38: " + getCheckMessage(MSG_KEY, "01000000000000000000000L"),
420             "131:20: " + getCheckMessage(MSG_KEY, "378"),
421             "140:52: " + getCheckMessage(MSG_KEY, "27"),
422             "143:53: " + getCheckMessage(MSG_KEY, "3"),
423             "143:56: " + getCheckMessage(MSG_KEY, "3"),
424             "143:59: " + getCheckMessage(MSG_KEY, "3"),
425             "143:62: " + getCheckMessage(MSG_KEY, "3"),
426             "160:16: " + getCheckMessage(MSG_KEY, "31"),
427             "165:16: " + getCheckMessage(MSG_KEY, "42"),
428             "170:16: " + getCheckMessage(MSG_KEY, "13"),
429             "174:15: " + getCheckMessage(MSG_KEY, "21"),
430             "178:15: " + getCheckMessage(MSG_KEY, "37"),
431             "182:15: " + getCheckMessage(MSG_KEY, "101"),
432             "185:42: " + getCheckMessage(MSG_KEY, "42"),
433             "189:48: " + getCheckMessage(MSG_KEY, "43"),
434             "193:42: " + getCheckMessage(MSG_KEY, "-44"),
435             "197:48: " + getCheckMessage(MSG_KEY, "-45"),
436             "209:63: " + getCheckMessage(MSG_KEY, "62"),
437         };
438         verify(checkConfig, getPath("InputMagicNumber.java"), expected);
439     }
440 }