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