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.blocks;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_ALONE;
23  import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_BREAK_BEFORE;
24  import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_NEW;
25  import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_SAME;
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertTrue;
28  import static org.junit.Assert.fail;
29  
30  import org.junit.Test;
31  
32  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
33  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
34  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
35  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
36  
37  public class RightCurlyCheckTest extends AbstractModuleTestSupport {
38      @Override
39      protected String getPackageLocation() {
40          return "com/puppycrawl/tools/checkstyle/checks/blocks/rightcurly";
41      }
42  
43      /* Additional test for jacoco, since valueOf()
44       * is generated by javac and jacoco reports that
45       * valueOf() is uncovered.
46       */
47      @Test
48      public void testRightCurlyOptionValueOf() {
49          final RightCurlyOption option = RightCurlyOption.valueOf("ALONE");
50          assertEquals("Invalid valueOf result", RightCurlyOption.ALONE, option);
51      }
52  
53      @Test
54      public void testDefault() throws Exception {
55          final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
56          final String[] expected = {
57              "25:17: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 17),
58              "28:17: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 17),
59              "40:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
60              "44:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
61              "93:27: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 27),
62          };
63          verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
64      }
65  
66      @Test
67      public void testSame() throws Exception {
68          final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
69          checkConfig.addAttribute("option", RightCurlyOption.SAME.toString());
70          final String[] expected = {
71              "25:17: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 17),
72              "28:17: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 17),
73              "40:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
74              "44:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
75              "93:27: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 27),
76          };
77          verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
78      }
79  
80      @Test
81      public void testSameOmitOneLiners() throws Exception {
82          final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
83          checkConfig.addAttribute("option", RightCurlyOption.SAME.toString());
84          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
85          verify(checkConfig, getPath("InputRightCurlyNameForOneLiners.java"), expected);
86      }
87  
88      @Test
89      public void testAlone() throws Exception {
90          final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
91          checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
92          final String[] expected = {
93              "93:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27),
94              "97:72: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 72),
95          };
96          verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
97      }
98  
99      @Test
100     public void testNewLine() throws Exception {
101         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
102         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
103         checkConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF, CTOR_DEF");
104         checkConfig.addAttribute("shouldStartLine", "true");
105         final String[] expected = {
106             "111:5: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 5),
107             "111:6: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 6),
108             "122:5: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 5),
109             "122:6: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 6),
110             "136:6: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 6),
111         };
112         verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
113     }
114 
115     @Test
116     public void testShouldStartLine() throws Exception {
117         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
118         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
119         checkConfig.addAttribute("shouldStartLine", "false");
120         final String[] expected = {
121             "93:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27),
122             "97:72: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 72),
123         };
124         verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
125     }
126 
127     @Test
128     public void testMethodCtorNamedClassClosingBrace() throws Exception {
129         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
130         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
131         checkConfig.addAttribute("shouldStartLine", "false");
132         final String[] expected = {
133             "93:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27),
134             "97:72: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 72),
135         };
136         verify(checkConfig, getPath("InputRightCurlyLeft.java"), expected);
137     }
138 
139     @Test
140     public void testForceLineBreakBefore() throws Exception {
141         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
142         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
143         checkConfig.addAttribute("tokens", "LITERAL_FOR,"
144                 + "LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT");
145         final String[] expected = {
146             "35:43: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 43),
147             "41:71: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 71),
148             "47:25: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 25),
149         };
150         verify(checkConfig, getPath("InputRightCurlyLineBreakBefore.java"), expected);
151     }
152 
153     @Test
154     public void testForceLineBreakBefore2() throws Exception {
155         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
156         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
157         verify(checkConfig, getPath("InputRightCurlyLineBreakBefore.java"), expected);
158     }
159 
160     @Test
161     public void testNullPointerException() throws Exception {
162         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
163         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
164         checkConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, "
165             + "LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT");
166         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
167         verify(checkConfig, getPath("InputRightCurlyEmptyAbstractMethod.java"), expected);
168     }
169 
170     @Test
171     public void testWithAnnotations() throws Exception {
172         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
173         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
174         checkConfig.addAttribute("tokens", "LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, "
175             + "LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, "
176             + "LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT");
177         final String[] expected = {
178             "8:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77),
179             "11:65: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 65),
180             "22:46: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 46),
181             "26:31: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 31),
182             "29:35: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 35),
183             "32:36: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 36),
184             "38:73: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 73),
185             "40:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37),
186             "45:58: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 58),
187             "47:97: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 97),
188             "50:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30),
189             "53:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30),
190             "60:38: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 38),
191             "67:62: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 62),
192             "76:28: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 28),
193             "78:21: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 21),
194             "80:20: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 20),
195             "82:14: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 14),
196             "93:26: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 26),
197             "103:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29),
198             "107:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29),
199             "111:52: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 52),
200             "111:112: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 112),
201             "114:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 18),
202             "118:23: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 23),
203             "121:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37),
204             "123:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30),
205             "127:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77),
206             "136:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
207             "138:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
208             "138:33: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 33),
209             "148:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
210             "150:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75),
211             "151:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77),
212             "151:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93),
213             "152:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77),
214             "153:77: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 77),
215             "153:93: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 93),
216             "159:37: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 37),
217             "166:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37),
218             "181:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
219             "188:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
220             "188:13: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 13),
221             "197:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
222             "197:10: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 10),
223             "201:54: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 54),
224             "201:55: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 55),
225             "204:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75),
226             "204:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76),
227             "204:77: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 77),
228             "208:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76),
229             "216:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27),
230 
231         };
232         verify(checkConfig, getPath("InputRightCurlyAnnotations.java"), expected);
233     }
234 
235     @Test
236     public void testAloneOrSingleLine() throws Exception {
237         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
238         checkConfig.addAttribute("option", RightCurlyOption.ALONE_OR_SINGLELINE.toString());
239         checkConfig.addAttribute("tokens", "LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, "
240             + "LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, "
241             + "LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT");
242         final String[] expected = {
243             "60:26: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 26),
244             "69:29: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 29),
245             "74:52: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 52),
246             "77:18: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 18),
247             "85:30: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 30),
248             "97:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
249             "99:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
250             "119:37: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 37),
251             "126:37: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 37),
252             "148:13: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 13),
253             "157:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
254             "157:10: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 10),
255             "161:54: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 54),
256             "161:55: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 55),
257             "164:75: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 75),
258             "164:76: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 76),
259             "164:77: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 77),
260             "176:27: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 27),
261             "182:24: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 24),
262             "185:24: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 24),
263             "188:24: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 24),
264         };
265         verify(checkConfig, getPath("InputRightCurlyAloneOrSingleline.java"), expected);
266     }
267 
268     @Test
269     public void testCatchWithoutFinally() throws Exception {
270         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
271         final String[] expected = {
272             "15:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
273         };
274         verify(checkConfig, getPath("InputRightCurly.java"), expected);
275     }
276 
277     @Test
278     public void testSingleLineClass() throws Exception {
279         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
280         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
281         checkConfig.addAttribute("tokens", "CLASS_DEF");
282         final String[] expected = {
283             "24:37: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 37),
284         };
285         verify(checkConfig, getPath("InputRightCurly.java"), expected);
286     }
287 
288     @Test
289     public void testInvalidOption() throws Exception {
290         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
291         checkConfig.addAttribute("option", "invalid_option");
292 
293         try {
294             final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
295 
296             verify(checkConfig, getPath("InputRightCurly.java"), expected);
297             fail("exception expected");
298         }
299         catch (CheckstyleException ex) {
300             final String messageStart =
301                 "cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - "
302                     + "Cannot set property 'option' to 'invalid_option' in module";
303             assertTrue("Invalid exception message, should start with: " + messageStart,
304                 ex.getMessage().startsWith(messageStart));
305         }
306     }
307 
308     @Test
309     public void testRightCurlySameAndLiteralDo() throws Exception {
310         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
311         checkConfig.addAttribute("option", RightCurlyOption.SAME.toString());
312         checkConfig.addAttribute("tokens", "LITERAL_DO");
313         final String[] expected = {
314             "62:9: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 9),
315             "67:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
316             "83:9: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 9),
317         };
318         verify(checkConfig, getPath("InputRightCurlyDoWhile.java"), expected);
319     }
320 
321     @Test
322     public void testTryWithResourceSame() throws Exception {
323         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
324         checkConfig.addAttribute("option", RightCurlyOption.SAME.toString());
325         final String[] expected = {
326             "11:9: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 9),
327             "24:67: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 67),
328             "35:15: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 15),
329             "37:13: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 13),
330         };
331         verify(checkConfig, getPath("InputRightCurlyTryResource.java"), expected);
332     }
333 
334     @Test
335     public void testTryWithResourceAlone() throws Exception {
336         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
337         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
338         final String[] expected = {
339             "19:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
340             "24:67: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 67),
341             "25:35: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 35),
342             "27:92: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 92),
343             "33:67: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 67),
344             "35:15: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 15),
345             "37:13: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 13),
346         };
347         verify(checkConfig, getPath("InputRightCurlyTryResource.java"), expected);
348     }
349 
350     @Test
351     public void testTryWithResourceAloneSingle() throws Exception {
352         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
353         checkConfig.addAttribute("option", RightCurlyOption.ALONE_OR_SINGLELINE.toString());
354         final String[] expected = {
355             "19:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
356             "35:15: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 15),
357             "37:13: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 13),
358         };
359         verify(checkConfig, getPath("InputRightCurlyTryResource.java"), expected);
360     }
361 
362     @Test
363     public void testBracePolicyAloneAndSinglelineIfBlocks() throws Exception {
364         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
365         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
366         final String[] expected = {
367             "5:32: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 32),
368             "7:45: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 45),
369             "7:47: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 47),
370         };
371         verify(checkConfig, getPath("InputRightCurlySingelineIfBlocks.java"), expected);
372     }
373 
374     @Test
375     public void testRightCurlyIsAloneLambda() throws Exception {
376         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
377         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
378         checkConfig.addAttribute("tokens", "LAMBDA");
379         final String[] expected = {
380             "14:74: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 74),
381             "17:49: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 49),
382             "35:5: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 5),
383             "45:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
384         };
385         verify(checkConfig, getPath("InputRightCurlyAloneLambda.java"), expected);
386     }
387 
388     @Test
389     public void testRightCurlyIsAloneOrSinglelineLambda() throws Exception {
390         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
391         checkConfig.addAttribute("option",
392             RightCurlyOption.ALONE_OR_SINGLELINE.toString());
393         checkConfig.addAttribute("tokens", "LAMBDA");
394         final String[] expected = {
395             "17:49: " + getCheckMessage(MSG_KEY_LINE_NEW, "}", 49),
396             "35:5: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 5),
397             "45:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
398             "47:58: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 58),
399         };
400         verify(checkConfig,
401             getPath("InputRightCurlyAloneOrSinglelineLambda.java"), expected);
402     }
403 
404     @Test
405     public void testRightCurlyIsSameLambda() throws Exception {
406         final DefaultConfiguration checkConfig = createModuleConfig(RightCurlyCheck.class);
407         checkConfig.addAttribute("option", RightCurlyOption.SAME.toString());
408         checkConfig.addAttribute("tokens", "LAMBDA");
409         final String[] expected = {
410             "17:49: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 49),
411             "35:5: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 5),
412             "40:13: " + getCheckMessage(MSG_KEY_LINE_SAME, "}", 13),
413             "53:30: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 30),
414             "68:20: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 20),
415             "73:20: " + getCheckMessage(MSG_KEY_LINE_BREAK_BEFORE, "}", 20),
416         };
417         verify(checkConfig,
418             getPath("InputRightCurlySameLambda.java"), expected);
419     }
420 }