1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.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.api.TokenTypes;
33 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
34
35 public class EmptyLineSeparatorCheckTest
36 extends AbstractModuleTestSupport {
37
38 @Override
39 protected String getPackageLocation() {
40 return "com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator";
41 }
42
43 @Test
44 public void testGetRequiredTokens() {
45 final EmptyLineSeparatorCheck checkObj = new EmptyLineSeparatorCheck();
46 assertWithMessage("EmptyLineSeparatorCheck#getRequiredTokens should return empty array "
47 + "by default")
48 .that(checkObj.getRequiredTokens())
49 .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
50 }
51
52 @Test
53 public void testDefault() throws Exception {
54
55 final String[] expected = {
56 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
57 "31:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
58 "34:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
59 "35:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
60 "39:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INSTANCE_INIT"),
61 "53:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
62 "58:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
63 "75:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
64 "106:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
65 };
66 verifyWithInlineConfigParser(
67 getPath("InputEmptyLineSeparator.java"), expected);
68 }
69
70 @Test
71 public void testAllowNoEmptyLineBetweenFields() throws Exception {
72
73 final String[] expected = {
74 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
75 "31:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
76 "35:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
77 "39:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INSTANCE_INIT"),
78 "53:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
79 "58:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
80 "75:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
81 "106:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
82 };
83 verifyWithInlineConfigParser(
84 getPath("InputEmptyLineSeparator2.java"), expected);
85 }
86
87 @Test
88 public void testHeader() throws Exception {
89 final String[] expected = {
90 "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
91 };
92 verifyWithInlineConfigParser(
93 getPath("InputEmptyLineSeparatorHeader.java"), expected);
94 }
95
96 @Test
97 public void testMultipleEmptyLinesBetweenClassMembers() throws Exception {
98 final String[] expected = {
99 "14:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "package"),
100 "17:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
101 "22:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "CLASS_DEF"),
102 "26:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
103 "31:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
104 "36:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
105 "38:33: " + getCheckMessage(MSG_MULTIPLE_LINES_AFTER, "}"),
106 };
107 verifyWithInlineConfigParser(
108 getPath("InputEmptyLineSeparatorMultipleEmptyLines.java"), expected);
109 }
110
111 @Test
112 public void testFormerArrayIndexOutOfBounds() throws Exception {
113 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
114 verifyWithInlineConfigParser(
115 getPath("InputEmptyLineSeparatorFormerException.java"), expected);
116 }
117
118 @Test
119 public void testAllowMultipleFieldInClass() throws Exception {
120 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
121 verifyWithInlineConfigParser(
122 getPath("InputEmptyLineSeparatorMultipleFieldsInClass.java"), expected);
123 }
124
125 @Test
126 public void testAllowMultipleImportSeparatedFromPackage() throws Exception {
127 final String[] expected = {
128 "13:78: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
129 };
130 verifyWithInlineConfigParser(
131 getPath("InputEmptyLineSeparatorMultipleImportEmptyClass.java"),
132 expected);
133 }
134
135 @Test
136 public void testImportSeparatedFromPackage() throws Exception {
137 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
138 verifyWithInlineConfigParser(
139 getPath("InputEmptyLineSeparatorImportSeparatedFromPackage.java"),
140 expected);
141 }
142
143 @Test
144 public void testStaticImport() throws Exception {
145 final String[] expected = {
146 "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
147 };
148 verifyWithInlineConfigParser(
149 getPath("InputEmptyLineSeparatorStaticImport.java"),
150 expected);
151 }
152
153 @Test
154 public void testBlockCommentNotSeparatedFromPackage() throws Exception {
155 final String[] expected = {
156 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
157 };
158 verifyWithInlineConfigParser(
159 getPath("InputEmptyLineSeparatorBlockCommentUnderPackage.java"),
160 expected);
161 }
162
163 @Test
164 public void testSingleCommentNotSeparatedFromPackage() throws Exception {
165 final String[] expected = {
166 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
167 };
168 verifyWithInlineConfigParser(
169 getPath("InputEmptyLineSeparatorSingleCommentUnderPackage.java"),
170 expected);
171 }
172
173 @Test
174 public void testClassDefinitionNotSeparatedFromPackage() throws Exception {
175 final String[] expected = {
176 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
177 };
178 verifyWithInlineConfigParser(
179 getPath("InputEmptyLineSeparatorModifierUnderPackage.java"),
180 expected);
181 }
182
183 @Test
184 public void testCommentAfterPackageWithImports() throws Exception {
185 final String[] expected = {
186 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
187 };
188 verifyWithInlineConfigParser(
189 getPath("InputEmptyLineSeparatorSingleLineCommentAfterPackage.java"),
190 expected);
191 }
192
193 @Test
194 public void testJavadocCommentAfterPackageWithImports() throws Exception {
195 final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
196 final String[] expected = {
197 "2:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
198 };
199 verify(checkConfig,
200 getPath("InputEmptyLineSeparatorJavadocCommentAfterPackage.java"),
201 expected);
202 }
203
204 @Test
205 public void testPackageImportsClassInSingleLine() throws Exception {
206 final String[] expected = {
207 "13:79: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
208 "13:101: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
209 };
210 verifyWithInlineConfigParser(
211 getPath("InputEmptyLineSeparatorPackageImportClassInOneLine.java"),
212 expected);
213 }
214
215 @Test
216 public void testEmptyLineAfterPackageForPackageAst() throws Exception {
217 final String[] expected = {
218 "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "/*"),
219 };
220 verifyWithInlineConfigParser(
221 getPath("InputEmptyLineSeparatorEmptyLineAfterPackageForPackageAst.java"),
222 expected);
223 }
224
225 @Test
226 public void testEmptyLineAfterPackageForImportAst() throws Exception {
227 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
228 verifyWithInlineConfigParser(
229 getPath("InputEmptyLineSeparatorEmptyLineAfterPackageForImportAst.java"),
230 expected);
231 }
232
233 @Test
234 public void testClassDefinitionAndCommentNotSeparatedFromPackage() throws Exception {
235 final String[] expected = {
236 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "//"),
237 "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
238 };
239 final String testFile =
240 "InputEmptyLineSeparatorClassDefinitionAndCommentNotSeparatedFromPackage.java";
241 verifyWithInlineConfigParser(
242 getPath(testFile), expected);
243 }
244
245 @Test
246 public void testBlockCommentSeparatedFromPackage() throws Exception {
247 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
248 verifyWithInlineConfigParser(
249 getPath("InputEmptyLineSeparatorBlockCommentSeparatedFromPackage.java"),
250 expected);
251 }
252
253 @Test
254 public void testSingleCommentSeparatedFromPackage() throws Exception {
255 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
256 verifyWithInlineConfigParser(
257 getPath("InputEmptyLineSeparatorSingleCommentSeparatedFromPackage.java"),
258 expected);
259 }
260
261 @Test
262 public void testEnumMembers() throws Exception {
263 final String[] expected = {
264 "22:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
265 "27:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
266 "28:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
267 "31:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "CTOR_DEF"),
268 "36:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
269 "40:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "STATIC_INIT"),
270 };
271 verifyWithInlineConfigParser(
272 getPath("InputEmptyLineSeparatorEnumMembers.java"), expected
273 );
274 }
275
276 @Test
277 public void testInterfaceFields() throws Exception {
278 final String[] expected = {
279 "21:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
280 "25:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
281 "34:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
282 "38:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
283 "45:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
284 };
285 verifyWithInlineConfigParser(
286 getPath("InputEmptyLineSeparatorInterfaceFields.java"), expected
287 );
288 }
289
290 @Test
291 public void testGetAcceptableTokens() {
292 final EmptyLineSeparatorCheck emptyLineSeparatorCheckObj = new EmptyLineSeparatorCheck();
293 final int[] actual = emptyLineSeparatorCheckObj.getAcceptableTokens();
294 final int[] expected = {
295 TokenTypes.PACKAGE_DEF,
296 TokenTypes.IMPORT,
297 TokenTypes.STATIC_IMPORT,
298 TokenTypes.CLASS_DEF,
299 TokenTypes.INTERFACE_DEF,
300 TokenTypes.ENUM_DEF,
301 TokenTypes.STATIC_INIT,
302 TokenTypes.INSTANCE_INIT,
303 TokenTypes.METHOD_DEF,
304 TokenTypes.CTOR_DEF,
305 TokenTypes.VARIABLE_DEF,
306 TokenTypes.RECORD_DEF,
307 TokenTypes.COMPACT_CTOR_DEF,
308 };
309 assertWithMessage("Default acceptable tokens are invalid")
310 .that(actual)
311 .isEqualTo(expected);
312 }
313
314 @Test
315 public void testPrePreviousLineEmptiness() throws Exception {
316 final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
317 checkConfig.addProperty("allowMultipleEmptyLines", "false");
318 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
319 verify(checkConfig,
320 getPath("InputEmptyLineSeparatorPrePreviousLineEmptiness.java"), expected);
321 }
322
323 @Test
324 public void testPrePreviousLineIsEmpty() throws Exception {
325 final DefaultConfiguration checkConfig = createModuleConfig(EmptyLineSeparatorCheck.class);
326 checkConfig.addProperty("allowMultipleEmptyLines", "false");
327 final String[] expected = {
328 "3:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "package"),
329 };
330 verify(checkConfig,
331 getPath("InputEmptyLineSeparatorPrePreviousLineIsEmpty.java"), expected);
332 }
333
334 @Test
335 public void testPreviousLineEmptiness() throws Exception {
336 final String[] expected = {
337 "21:30: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
338 "26:5: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
339 "32:67: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
340 "41:48: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
341 "51:21: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
342 };
343 verifyWithInlineConfigParser(
344 getPath("InputEmptyLineSeparatorPreviousLineEmptiness.java"), expected);
345 }
346
347 @Test
348 public void testDisAllowMultipleEmptyLinesInsideClassMembers() throws Exception {
349 final String[] expected = {
350 "18:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
351 "30:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
352 "36:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
353 "41:35: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
354 "46:11: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
355 "53:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
356 };
357 verifyWithInlineConfigParser(
358 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside.java"),
359 expected);
360 }
361
362 @Test
363 public void testAllowMultipleEmptyLinesInsideClassMembers() throws Exception {
364 final String[] expected = {
365 "53:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
366 };
367 verifyWithInlineConfigParser(
368 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside2.java"),
369 expected);
370 }
371
372 @Test
373 public void testImportsAndStaticImports() throws Exception {
374 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
375 verifyWithInlineConfigParser(
376 getPath("InputEmptyLineSeparatorImports.java"), expected);
377 }
378
379 @Test
380 public void testAllowPackageAnnotation() throws Exception {
381 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
382 verifyWithInlineConfigParser(
383 getPath("packageinfo/test1/package-info.java"),
384 expected);
385 }
386
387 @Test
388 public void testAllowJavadocBeforePackage() throws Exception {
389 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
390 verifyWithInlineConfigParser(
391 getPath("packageinfo/test2/package-info.java"),
392 expected);
393 }
394
395 @Test
396 public void testDisAllowBlockCommentBeforePackage() throws Exception {
397 final String[] expected = {
398 "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
399 };
400 verifyWithInlineConfigParser(
401 getPath("packageinfo/test3/package-info.java"),
402 expected);
403 }
404
405 @Test
406 public void testAllowSingleLineCommentPackage() throws Exception {
407 final String[] expected = {
408 "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
409 };
410 verifyWithInlineConfigParser(
411 getPath("packageinfo/test4/package-info.java"),
412 expected);
413 }
414
415 @Test
416 public void testNonPackageInfoWithJavadocBeforePackage() throws Exception {
417 final String[] expected = {
418 "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
419 };
420 verifyWithInlineConfigParser(
421 getPath("InputEmptyLineSeparatorNonPackageInfoWithJavadocBeforePackage.java"),
422 expected);
423 }
424
425 @Test
426 public void testClassOnly() throws Exception {
427 final String[] expected = {
428 "51:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
429 };
430 verifyWithInlineConfigParser(
431 getPath("InputEmptyLineSeparatorMultipleEmptyLinesInside3.java"),
432 expected);
433 }
434
435 @Test
436 public void testLineSeparationBeforeComments() throws Exception {
437 final String[] expected = {
438 "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
439 "16:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
440 "20:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
441 "25:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
442 "32:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
443 "43:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
444 "60:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
445 "71:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
446 "76:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "import"),
447 "82:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
448 "86:1: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
449 "94:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
450 "99:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
451 "106:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
452 "119:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
453 "132:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
454 "139:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
455 "149:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
456 "164:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
457 "181:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "CLASS_DEF"),
458 "187:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
459 "191:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
460 "197:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
461 "209:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
462 "222:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
463 "236:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
464 "239:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
465 "244:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "/*"),
466 "260:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
467 "269:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
468 "282:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
469 "287:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
470 "293:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
471 "301:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
472 "310:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
473 "316:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
474 "336:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
475 "344:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "//"),
476 };
477 verifyWithInlineConfigParser(
478 getPath("InputEmptyLineSeparatorWithComments.java"), expected);
479 }
480
481 @Test
482 public void testIgnoreEmptyLinesBeforeCommentsWhenItIsAllowed() throws Exception {
483 final String[] expected = {
484 "12:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
485 "239:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
486 };
487 verifyWithInlineConfigParser(
488 getPath("InputEmptyLineSeparatorWithComments2.java"), expected);
489 }
490
491 @Test
492 public void testNoViolationsOnEmptyLinesBeforeComments() throws Exception {
493 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
494 verifyWithInlineConfigParser(
495 getPath("InputEmptyLineSeparatorNoViolationOnEmptyLineBeforeComments.java"),
496 expected);
497 }
498
499 @Test
500 public void testEmptyLineSeparatorRecordsAndCompactCtors() throws Exception {
501 final String[] expected = {
502 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
503 "18:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "RECORD_DEF"),
504 "20:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
505 "21:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
506 "22:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
507 "23:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
508 "25:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "RECORD_DEF"),
509 "26:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
510 "28:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
511 "29:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
512 "30:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CTOR_DEF"),
513 "35:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
514 "36:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
515 "41:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "COMPACT_CTOR_DEF"),
516 "42:9: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
517 };
518
519 verifyWithInlineConfigParser(
520 getNonCompilablePath("InputEmptyLineSeparatorRecordsAndCompactCtors.java"),
521 expected);
522 }
523
524 @Test
525 public void testEmptyLineSeparatorRecordsAndCompactCtorsNoEmptyLines() throws Exception {
526
527 final String[] expected = {
528 "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
529 "17:27: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
530 "23:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
531 };
532
533 verifyWithInlineConfigParser(
534 getNonCompilablePath(
535 "InputEmptyLineSeparatorRecordsAndCompactCtorsNoEmptyLines.java"),
536 expected);
537 }
538
539 @Test
540 public void testEmptyLineSeparatorMultipleSingleTypeVariables() throws Exception {
541
542 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
543
544 verifyWithInlineConfigParser(
545 getPath("InputEmptyLineSeparatorSingleTypeVariables.java"),
546 expected);
547 }
548
549 @Test
550 public void testEmptyLineSeparatorEmptyLinesInsideClassMembersRecursive() throws Exception {
551 final String[] expected = {
552 "27:15: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
553 };
554 verifyWithInlineConfigParser(
555 getPath("InputEmptyLineSeparatorRecursive.java"),
556 expected);
557 }
558
559 @Test
560 public void testEmptyLineSeparatorNewMethodDef() throws Exception {
561 final String[] expected = {
562 "29:34: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
563 "38:26: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
564 };
565 verifyWithInlineConfigParser(
566 getPath("InputEmptyLineSeparatorNewMethodDef.java"),
567 expected);
568 }
569
570 @Test
571 public void testEmptyLineSeparatorPostFixCornerCases() throws Exception {
572 final String[] expected = {
573 "18:19: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
574 "32:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
575 "43:29: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
576 };
577 verifyWithInlineConfigParser(
578 getPath("InputEmptyLineSeparatorPostFixCornerCases.java"),
579 expected);
580 }
581
582 @Test
583 public void testEmptyLineSeparatorAnnotation() throws Exception {
584 final String[] expected = {
585 "18:22: " + getCheckMessage(MSG_MULTIPLE_LINES_AFTER, "}"),
586 };
587 verifyWithInlineConfigParser(
588 getPath("InputEmptyLineSeparatorAnnotations.java"),
589 expected);
590 }
591
592 @Test
593 public void testEmptyLineSeparatorWithEmoji() throws Exception {
594
595 final String[] expected = {
596 "22:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
597 "27:5: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
598 "33:15: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
599 "41:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
600 };
601 verifyWithInlineConfigParser(
602 getPath("InputEmptyLineSeparatorWithEmoji.java"),
603 expected);
604 }
605
606 @Test
607 public void testMultipleLines() throws Exception {
608 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
609 verifyWithInlineConfigParser(
610 getPath("InputEmptyLineSeparatorMultipleLines.java"),
611 expected);
612 }
613
614 @Test
615 public void testMultipleLines2() throws Exception {
616 final String[] expected = {
617 "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
618 };
619 verifyWithInlineConfigParser(
620 getPath("InputEmptyLineSeparatorMultipleLines2.java"),
621 expected);
622 }
623
624 @Test
625 public void testMultipleLines3() throws Exception {
626 final String[] expected = {
627 "24:5: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
628 };
629 verifyWithInlineConfigParser(
630 getNonCompilablePath("InputEmptyLineSeparatorMultipleLines3.java"),
631 expected);
632 }
633
634 }