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.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_MULTIPLE_LINES;
23  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_MULTIPLE_LINES_INSIDE;
24  import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_SHOULD_BE_SEPARATED;
25  
26  import org.junit.jupiter.api.Test;
27  
28  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
29  
30  public class EmptyLineSeparatorExamplesTest extends AbstractExamplesModuleTestSupport {
31      @Override
32      public String getPackageLocation() {
33          return "com/puppycrawl/tools/checkstyle/checks/whitespace/emptylineseparator";
34      }
35  
36      @Test
37      public void testExample1() throws Exception {
38          final String[] expected = {
39              "14:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
40              "15:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
41              "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
42              "19:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
43              "26:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
44          };
45  
46          verifyWithInlineConfigParser(getPath("Example1.java"), expected);
47      }
48  
49      @Test
50      public void testExample2() throws Exception {
51          final String[] expected = {
52              "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
53              "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
54          };
55  
56          verifyWithInlineConfigParser(getPath("Example2.java"), expected);
57      }
58  
59      @Test
60      public void testExample3() throws Exception {
61          final String[] expected = {
62              "18:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
63          };
64  
65          verifyWithInlineConfigParser(getPath("Example3.java"), expected);
66      }
67  
68      @Test
69      public void testExample4() throws Exception {
70          final String[] expected = {
71              "21:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
72              "28:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
73          };
74  
75          verifyWithInlineConfigParser(getPath("Example4.java"), expected);
76      }
77  
78      @Test
79      public void testExample5() throws Exception {
80          final String[] expected = {
81              "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
82              "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
83              "18:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
84              "28:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
85          };
86  
87          verifyWithInlineConfigParser(getPath("Example5.java"), expected);
88      }
89  
90      @Test
91      public void testExample6() throws Exception {
92          final String[] expected = {
93              "16:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
94              "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
95              "18:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
96              "21:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
97              "24:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
98              "27:3: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
99              "28:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
100         };
101 
102         verifyWithInlineConfigParser(getPath("Example6.java"), expected);
103     }
104 
105     @Test
106     public void testExample7() throws Exception {
107         final String[] expected = {
108             "17:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
109             "18:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
110             "19:1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "CLASS_DEF"),
111             "22:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "VARIABLE_DEF"),
112             "29:3: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "METHOD_DEF"),
113             "30:17: " + getCheckMessage(MSG_MULTIPLE_LINES_INSIDE),
114         };
115 
116         verifyWithInlineConfigParser(getPath("Example7.java"), expected);
117     }
118 }