View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.whitespace;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_MULTIPLE_LINES;
24  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_MULTIPLE_LINES_AFTER;
25  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_MULTIPLE_LINES_INSIDE;
26  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_SHOULD_BE_SEPARATED;
27  
28  import org.junit.jupiter.api.Test;
29  
30  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
31  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
32  import com.puppycrawl.tools.checkstyle.TreeWalker;
33  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
34  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
35  
36  public class EmptyLineSeparatorCheckTest
37      extends AbstractModuleTestSupport {
38  
39      @Override
40      public String getPackageLocation() {
41          return "com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator";
42      }
43  
44      @Test
45      public void testGetRequiredTokens() {
46          final EmptyLineSeparatorCheck checkObj = new EmptyLineSeparatorCheck();
47          assertWithMessage("EmptyLineSeparatorCheck#getRequiredTokens should return empty array "
48                  + "by default")
49              .that(checkObj.getRequiredTokens())
50              .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
51      }
52  
53      @Test
54      public void testMultipleLinesEmptyWithJavadoc() throws Exception {
55  
56          final String[] expected = {
57              "27:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
58              "43:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
59              "51:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
60              "56:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
61              "65:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
62              "75:13: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
63              "86:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
64              "93:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
65              "99:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
66          };
67          verifyWithInlineXmlConfig(
68                  getPath("InputEmptyLineSeparatorWithJavadoc.java"), expected);
69      }
70  
71      @Test
72      public void testMultipleLinesEmptyWithJavadoc2() throws Exception {
73  
74          final String[] expected = {
75              "65:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
76              "70:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
77              "75:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
78              "85:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
79              "96:7: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
80              "107:7: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
81          };
82          verifyWithInlineXmlConfig(
83                  getPath("InputEmptyLineSeparatorWithJavadoc2.java"), expected);
84      }
85  
86      @Test
87      public void testSeparationOfClassAndPackageWithComment() throws Exception {
88  
89          final String[] expected = {
90              "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
91              "13:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
92          };
93  
94          verifyWithInlineXmlConfig(
95                  getPath("InputEmptyLineSeparatorClassPackageSeparation.java"), expected);
96      }
97  
98      /**
99       * Config is defined in the method because indexOutOfBond test is also required.
100      */
101     @Test
102     public void testCompactNoPackage() throws Exception {
103 
104         final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
105         checkConfig.addProperty("allowMultipleEmptyLines", "false");
106 
107         final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
108         treeWalkerConfig.addChild(checkConfig);
109 
110         final DefaultConfiguration checkerConfig = createRootConfig(treeWalkerConfig);
111 
112         final String[] expected = {
113             "7:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
114             "11:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
115             "16:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
116             "20:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
117             "25:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
118             "29:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
119             "34:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
120         };
121 
122         verify(checkerConfig, getNonCompilablePath("InputEmptyLineSeparatorCompactNoPackage.java"),
123             expected);
124     }
125 
126     @Test
127     public void testCompactSourceFile() throws Exception {
128         final String[] expected = {
129             "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
130             "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
131             "23:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
132         };
133 
134         verifyWithInlineConfigParser(
135                 getNonCompilablePath("InputEmptyLineSeparatorCompactSourceFile.java"), expected);
136     }
137 
138     @Test
139     public void testCompactSourceFileMultipleEmptyLines() throws Exception {
140         final String[] expected = {
141             "18:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
142             "22:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
143         };
144 
145         verifyWithInlineConfigParser(
146                 getNonCompilablePath(
147                     "InputEmptyLineSeparatorCompactSourceFileMultipleEmptyLines.java"), expected);
148     }
149 
150     @Test
151     public void testMethodInAnonymousClass() throws Exception {
152         final String[] expected = {
153             "21:9: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
154         };
155 
156         verifyWithInlineConfigParser(
157                 getPath("InputEmptyLineSeparatorMethodInAnonymousClass.java"), expected);
158     }
159 
160     /**
161      * Config is defined in the method because strictly the file with one line
162      * is required to be tested.
163      */
164     @Test
165     public void testMultipleEmptyLinesInOneLine() throws Exception {
166         final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
167         checkConfig.addProperty("allowNoEmptyLineBetweenFields", "true");
168         checkConfig.addProperty("allowMultipleEmptyLines", "false");
169         checkConfig.addProperty("allowMultipleEmptyLinesInsideClassMembers", "false");
170 
171         final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
172         treeWalkerConfig.addChild(checkConfig);
173 
174         final DefaultConfiguration checkerConfig = createRootConfig(treeWalkerConfig);
175 
176         final String[] expected = {
177             "1:79: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
178         };
179 
180         verify(checkerConfig, getPath("InputEmptyLineSeparatorOneLine.java"), expected);
181     }
182 
183     @Test
184     public void testDefault() throws Exception {
185 
186         final String[] expected = {
187             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
188             "31:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
189             "34:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
190             "35:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
191             "39:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INSTANCE_INIT"),
192             "53:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
193             "58:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
194             "75:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
195             "106:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
196         };
197         verifyWithInlineConfigParser(
198                 getPath("InputEmptyLineSeparator.java"), expected);
199     }
200 
201     @Test
202     public void testAllowNoEmptyLineBetweenFields() throws Exception {
203 
204         final String[] expected = {
205             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
206             "31:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
207             "35:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
208             "39:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INSTANCE_INIT"),
209             "53:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
210             "58:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
211             "75:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
212             "106:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
213         };
214         verifyWithInlineConfigParser(
215                 getPath("InputEmptyLineSeparator2.java"), expected);
216     }
217 
218     @Test
219     public void testHeader() throws Exception {
220         final String[] expected = {
221             "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
222         };
223         verifyWithInlineConfigParser(
224                 getPath("InputEmptyLineSeparatorHeader.java"), expected);
225     }
226 
227     @Test
228     public void testMultipleEmptyLinesBetweenClassMembers() throws Exception {
229         final String[] expected = {
230             "14:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "package"),
231             "17:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
232             "22:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "CLASS_DEF"),
233             "26:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
234             "31:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
235             "36:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
236             "38:33: " + getCheckMessage(MSG_MULTIPLE_LINES_AFTER, "}"),
237         };
238         verifyWithInlineConfigParser(
239                 getPath("InputEmptyLineSeparatorMultipleEmptyLines.java"), expected);
240     }
241 
242     @Test
243     public void testFormerArrayIndexOutOfBounds() throws Exception {
244         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
245         verifyWithInlineConfigParser(
246                 getPath("InputEmptyLineSeparatorFormerException.java"), expected);
247     }
248 
249     @Test
250     public void testAllowMultipleFieldInClass() throws Exception {
251         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
252         verifyWithInlineConfigParser(
253                 getPath("InputEmptyLineSeparatorMultipleFieldsInClass.java"), expected);
254     }
255 
256     @Test
257     public void testAllowMultipleImportSeparatedFromPackage() throws Exception {
258         final String[] expected = {
259             "13:78: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
260         };
261         verifyWithInlineConfigParser(
262                 getPath("InputEmptyLineSeparatorMultipleImportEmptyClass.java"),
263             expected);
264     }
265 
266     @Test
267     public void testImportSeparatedFromPackage() throws Exception {
268         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
269         verifyWithInlineConfigParser(
270                 getPath("InputEmptyLineSeparatorImportSeparatedFromPackage.java"),
271             expected);
272     }
273 
274     @Test
275     public void testStaticImport() throws Exception {
276         final String[] expected = {
277             "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
278         };
279         verifyWithInlineConfigParser(
280                 getPath("InputEmptyLineSeparatorStaticImport.java"),
281             expected);
282     }
283 
284     @Test
285     public void testModuleImport() throws Exception {
286         final String[] expected = {
287             "19:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
288         };
289         verifyWithInlineConfigParser(
290                 getNonCompilablePath("InputEmptyLineSeparatorModuleImport.java"),
291             expected);
292     }
293 
294     @Test
295     public void testModuleImportSeparated() throws Exception {
296         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
297         verifyWithInlineConfigParser(
298                 getNonCompilablePath("InputEmptyLineSeparatorModuleImportSeparated.java"),
299             expected);
300     }
301 
302     @Test
303     public void testModuleImportMultipleEmptyLines() throws Exception {
304         final String[] expected = {
305             "20:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
306             "21:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
307         };
308         verifyWithInlineConfigParser(
309                 getNonCompilablePath("InputEmptyLineSeparatorModuleImportMultipleEmptyLines.java"),
310             expected);
311     }
312 
313     @Test
314     public void testBlockCommentNotSeparatedFromPackage() throws Exception {
315         final String[] expected = {
316             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
317         };
318         verifyWithInlineConfigParser(
319                 getPath("InputEmptyLineSeparatorBlockCommentUnderPackage.java"),
320             expected);
321     }
322 
323     @Test
324     public void testSingleCommentNotSeparatedFromPackage() throws Exception {
325         final String[] expected = {
326             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
327         };
328         verifyWithInlineConfigParser(
329                 getPath("InputEmptyLineSeparatorSingleCommentUnderPackage.java"),
330             expected);
331     }
332 
333     @Test
334     public void testClassDefinitionNotSeparatedFromPackage() throws Exception {
335         final String[] expected = {
336             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
337         };
338         verifyWithInlineConfigParser(
339                 getPath("InputEmptyLineSeparatorModifierUnderPackage.java"),
340             expected);
341     }
342 
343     @Test
344     public void testCommentAfterPackageWithImports() throws Exception {
345         final String[] expected = {
346             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
347         };
348         verifyWithInlineConfigParser(
349                 getPath("InputEmptyLineSeparatorSingleLineCommentAfterPackage.java"),
350                 expected);
351     }
352 
353     @Test
354     public void testJavadocCommentAfterPackageWithImports() throws Exception {
355         final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
356         final String[] expected = {
357             "2:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
358         };
359         verify(checkConfig,
360                 getPath("InputEmptyLineSeparatorJavadocCommentAfterPackage.java"),
361                 expected);
362     }
363 
364     @Test
365     public void testPackageImportsClassInSingleLine() throws Exception {
366         final String[] expected = {
367             "13:79: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
368             "13:101: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
369         };
370         verifyWithInlineConfigParser(
371                 getPath("InputEmptyLineSeparatorPackageImportClassInOneLine.java"),
372                 expected);
373     }
374 
375     @Test
376     public void testEmptyLineAfterPackageForPackageAst() throws Exception {
377         final String[] expected = {
378             "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
379         };
380         verifyWithInlineConfigParser(
381                 getPath("InputEmptyLineSeparatorEmptyLineAfterPackageForPackageAst.java"),
382                 expected);
383     }
384 
385     @Test
386     public void testEmptyLineAfterPackageForImportAst() throws Exception {
387         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
388         verifyWithInlineConfigParser(
389                 getPath("InputEmptyLineSeparatorEmptyLineAfterPackageForImportAst.java"),
390                 expected);
391     }
392 
393     @Test
394     public void testClassDefinitionAndCommentNotSeparatedFromPackage() throws Exception {
395         final String[] expected = {
396             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
397             "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
398         };
399         final String testFile =
400             "InputEmptyLineSeparatorClassDefinitionAndCommentNotSeparatedFromPackage.java";
401         verifyWithInlineConfigParser(
402                 getPath(testFile), expected);
403     }
404 
405     @Test
406     public void testBlockCommentSeparatedFromPackage() throws Exception {
407         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
408         verifyWithInlineConfigParser(
409                 getPath("InputEmptyLineSeparatorBlockCommentSeparatedFromPackage.java"),
410             expected);
411     }
412 
413     @Test
414     public void testSingleCommentSeparatedFromPackage() throws Exception {
415         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
416         verifyWithInlineConfigParser(
417                 getPath("InputEmptyLineSeparatorSingleCommentSeparatedFromPackage.java"),
418             expected);
419     }
420 
421     @Test
422     public void testEnumMembers() throws Exception {
423         final String[] expected = {
424             "22:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
425             "27:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
426             "28:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
427             "31:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "CTOR_DEF"),
428             "36:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
429             "40:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "STATIC_INIT"),
430         };
431         verifyWithInlineConfigParser(
432             getPath("InputEmptyLineSeparatorEnumMembers.java"), expected
433         );
434     }
435 
436     @Test
437     public void testInterfaceFields() throws Exception {
438         final String[] expected = {
439             "21:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
440             "25:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
441             "34:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
442             "38:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
443             "45:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
444         };
445         verifyWithInlineConfigParser(
446             getPath("InputEmptyLineSeparatorInterfaceFields.java"), expected
447         );
448     }
449 
450     @Test
451     public void testGetAcceptableTokens() {
452         final EmptyLineSeparatorCheck emptyLineSeparatorCheckObj = new EmptyLineSeparatorCheck();
453         final int[] actual = emptyLineSeparatorCheckObj.getAcceptableTokens();
454         final int[] expected = {
455             TokenTypes.PACKAGE_DEF,
456             TokenTypes.IMPORT,
457             TokenTypes.STATIC_IMPORT,
458             TokenTypes.MODULE_IMPORT,
459             TokenTypes.CLASS_DEF,
460             TokenTypes.INTERFACE_DEF,
461             TokenTypes.ENUM_DEF,
462             TokenTypes.STATIC_INIT,
463             TokenTypes.INSTANCE_INIT,
464             TokenTypes.METHOD_DEF,
465             TokenTypes.CTOR_DEF,
466             TokenTypes.VARIABLE_DEF,
467             TokenTypes.RECORD_DEF,
468             TokenTypes.COMPACT_CTOR_DEF,
469         };
470         assertWithMessage("Default acceptable tokens are invalid")
471             .that(actual)
472             .isEqualTo(expected);
473     }
474 
475     @Test
476     public void testPrePreviousLineEmptiness() throws Exception {
477         final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
478         checkConfig.addProperty("allowMultipleEmptyLines", "false");
479         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
480         verify(checkConfig,
481             getPath("InputEmptyLineSeparatorPrePreviousLineEmptiness.java"), expected);
482     }
483 
484     @Test
485     public void testPrePreviousLineIsEmpty() throws Exception {
486         final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
487         checkConfig.addProperty("allowMultipleEmptyLines", "false");
488         final String[] expected = {
489             "3:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "package"),
490         };
491         verify(checkConfig,
492                 getPath("InputEmptyLineSeparatorPrePreviousLineIsEmpty.java"), expected);
493     }
494 
495     @Test
496     public void testPreviousLineEmptiness() throws Exception {
497         final String[] expected = {
498             "21:30: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
499             "26:5: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
500             "32:67: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
501             "41:48: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
502             "51:21: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
503         };
504         verifyWithInlineConfigParser(
505                 getPath("InputEmptyLineSeparatorPreviousLineEmptiness.java"), expected);
506     }
507 
508     @Test
509     public void testDisAllowMultipleEmptyLinesInsideClassMembers() throws Exception {
510         final String[] expected = {
511             "18:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
512             "30:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
513             "36:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
514             "41:35: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
515             "46:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
516             "53:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
517         };
518         verifyWithInlineConfigParser(
519                 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside.java"),
520                 expected);
521     }
522 
523     @Test
524     public void testDisAllowMultipleEmptyLinesInsideClassMembers1() throws Exception {
525         final String[] expected = {
526             "23:27: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
527             "26:19: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
528             "31:64: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
529             "36:19: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
530         };
531         verifyWithInlineConfigParser(
532                 getPath("InputEmptyLineSeparatorInsideClassMembers.java"),
533                 expected);
534     }
535 
536     @Test
537     public void testAllowMultipleEmptyLinesInsideClassMembers() throws Exception {
538         final String[] expected = {
539             "53:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
540         };
541         verifyWithInlineConfigParser(
542                 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside2.java"),
543                 expected);
544     }
545 
546     @Test
547     public void testImportsAndStaticImports() throws Exception {
548         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
549         verifyWithInlineConfigParser(
550                 getPath("InputEmptyLineSeparatorImports.java"), expected);
551     }
552 
553     @Test
554     public void testAllowPackageAnnotation() throws Exception {
555         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
556         verifyWithInlineConfigParser(
557                 getPath("packageinfo/test1/package-info.java"),
558                 expected);
559     }
560 
561     @Test
562     public void testAllowJavadocBeforePackage() throws Exception {
563         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
564         verifyWithInlineConfigParser(
565                 getPath("packageinfo/test2/package-info.java"),
566                 expected);
567     }
568 
569     @Test
570     public void testDisAllowBlockCommentBeforePackage() throws Exception {
571         final String[] expected = {
572             "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
573         };
574         verifyWithInlineConfigParser(
575                 getPath("packageinfo/test3/package-info.java"),
576                 expected);
577     }
578 
579     @Test
580     public void testAllowSingleLineCommentPackage() throws Exception {
581         final String[] expected = {
582             "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
583         };
584         verifyWithInlineConfigParser(
585                 getPath("packageinfo/test4/package-info.java"),
586                 expected);
587     }
588 
589     @Test
590     public void testBlockCommentsBeforePackage() throws Exception {
591         final String[] expected = {
592             "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
593         };
594         verifyWithInlineConfigParser(
595                 getPath("packageinfo/test5/package-info.java"),
596                 expected);
597     }
598 
599     @Test
600     public void testNonPackageInfoWithJavadocBeforePackage() throws Exception {
601         final String[] expected = {
602             "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
603         };
604         verifyWithInlineConfigParser(
605                 getPath("InputEmptyLineSeparatorNonPackageInfoWithJavadocBeforePackage.java"),
606                 expected);
607     }
608 
609     @Test
610     public void testClassOnly() throws Exception {
611         final String[] expected = {
612             "51:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
613         };
614         verifyWithInlineConfigParser(
615                 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside3.java"),
616                 expected);
617     }
618 
619     @Test
620     public void testLineSeparationBeforeComments() throws Exception {
621         final String[] expected = {
622             "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
623             "16:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
624             "20:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
625             "25:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
626             "32:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
627             "43:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
628             "60:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
629             "71:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
630             "76:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
631             "82:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
632             "86:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
633             "94:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
634             "99:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
635             "106:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
636             "119:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
637             "132:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
638             "139:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
639             "149:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
640             "164:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
641             "181:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "CLASS_DEF"),
642             "187:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
643             "191:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
644             "197:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
645             "209:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
646             "222:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
647             "236:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
648             "239:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
649             "244:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
650             "260:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
651             "269:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
652             "282:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
653             "287:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
654             "293:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
655             "301:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
656             "310:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
657             "316:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
658             "336:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
659             "344:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
660         };
661         verifyWithInlineConfigParser(
662                 getPath("InputEmptyLineSeparatorWithComments.java"), expected);
663     }
664 
665     @Test
666     public void testIgnoreEmptyLinesBeforeCommentsWhenItIsAllowed() throws Exception {
667         final String[] expected = {
668             "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
669             "239:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
670         };
671         verifyWithInlineConfigParser(
672                 getPath("InputEmptyLineSeparatorWithComments2.java"), expected);
673     }
674 
675     @Test
676     public void testNoViolationsOnEmptyLinesBeforeComments() throws Exception {
677         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
678         verifyWithInlineConfigParser(
679                 getPath("InputEmptyLineSeparatorNoViolationOnEmptyLineBeforeComments.java"),
680                 expected);
681     }
682 
683     @Test
684     public void testEmptyLineSeparatorRecordsAndCompactCtors() throws Exception {
685         final String[] expected = {
686             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
687             "18:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "RECORD_DEF"),
688             "20:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
689             "21:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
690             "22:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
691             "23:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
692             "25:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "RECORD_DEF"),
693             "26:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
694             "28:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
695             "29:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
696             "30:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
697             "35:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
698             "36:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
699             "41:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
700             "42:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
701         };
702 
703         verifyWithInlineConfigParser(
704                 getPath("InputEmptyLineSeparatorRecordsAndCompactCtors.java"),
705                 expected);
706     }
707 
708     @Test
709     public void testEmptyLineSeparatorRecordsAndCompactCtorsNoEmptyLines() throws Exception {
710 
711         final String[] expected = {
712             "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
713             "17:27: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
714             "23:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
715         };
716 
717         verifyWithInlineConfigParser(
718                 getPath(
719                         "InputEmptyLineSeparatorRecordsAndCompactCtorsNoEmptyLines.java"),
720                 expected);
721     }
722 
723     @Test
724     public void testEmptyLineSeparatorMultipleSingleTypeVariables() throws Exception {
725 
726         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
727 
728         verifyWithInlineConfigParser(
729                 getPath("InputEmptyLineSeparatorSingleTypeVariables.java"),
730                 expected);
731     }
732 
733     @Test
734     public void testEmptyLineSeparatorEmptyLinesInsideClassMembersRecursive() throws Exception {
735         final String[] expected = {
736             "27:15: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
737         };
738         verifyWithInlineConfigParser(
739                 getPath("InputEmptyLineSeparatorRecursive.java"),
740                 expected);
741     }
742 
743     @Test
744     public void testEmptyLineSeparatorNewMethodDef() throws Exception {
745         final String[] expected = {
746             "29:34: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
747             "38:26: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
748         };
749         verifyWithInlineConfigParser(
750                 getPath("InputEmptyLineSeparatorNewMethodDef.java"),
751                 expected);
752     }
753 
754     @Test
755     public void testEmptyLineSeparatorPostFixCornerCases() throws Exception {
756         final String[] expected = {
757             "18:19: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
758             "32:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
759             "43:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
760         };
761         verifyWithInlineConfigParser(
762                 getPath("InputEmptyLineSeparatorPostFixCornerCases.java"),
763                 expected);
764     }
765 
766     @Test
767     public void testEmptyLineSeparatorAnnotation() throws Exception {
768         final String[] expected = {
769             "18:22: " + getCheckMessage(MSG_MULTIPLE_LINES_AFTER, "}"),
770         };
771         verifyWithInlineConfigParser(
772                 getPath("InputEmptyLineSeparatorAnnotations.java"),
773                 expected);
774     }
775 
776     @Test
777     public void testEmptyLineSeparatorWithEmoji() throws Exception {
778 
779         final String[] expected = {
780             "22:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
781             "27:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
782             "33:15: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
783             "41:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
784         };
785         verifyWithInlineConfigParser(
786                 getPath("InputEmptyLineSeparatorWithEmoji.java"),
787                 expected);
788     }
789 
790     @Test
791     public void testMultipleLines() throws Exception {
792         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
793         verifyWithInlineConfigParser(
794                 getPath("InputEmptyLineSeparatorMultipleLines.java"),
795                 expected);
796     }
797 
798     @Test
799     public void testMultipleLines2() throws Exception {
800         final String[] expected = {
801             "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
802         };
803         verifyWithInlineConfigParser(
804                 getPath("InputEmptyLineSeparatorMultipleLines2.java"),
805                 expected);
806     }
807 
808     @Test
809     public void testMultipleLines3() throws Exception {
810         final String[] expected = {
811             "24:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
812         };
813         verifyWithInlineConfigParser(
814                 getPath("InputEmptyLineSeparatorMultipleLines3.java"),
815                 expected);
816     }
817 
818     @Test
819     public void testEmptyLineSeparator() throws Exception {
820         final String[] expected = {
821             "16:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "package"),
822             "21:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "CLASS_DEF"),
823             "25:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
824         };
825         verifyWithInlineConfigParser(
826                 getPath("InputEmptyLineSeparator3.java"),
827                 expected
828         );
829     }
830 
831 }