View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 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.FileTabCharacterCheck.MSG_CONTAINS_TAB;
23  import static com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck.MSG_FILE_CONTAINS_TAB;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  
29  public class FileTabCharacterCheckTest
30      extends AbstractModuleTestSupport {
31  
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/whitespace/filetabcharacter";
35      }
36  
37      @Test
38      public void testDefault() throws Exception {
39          final String[] expected = {
40              "22:25: " + getCheckMessage(MSG_FILE_CONTAINS_TAB),
41          };
42          verifyWithInlineConfigParser(
43                  getPath("InputFileTabCharacterSimple.java"),
44              expected);
45      }
46  
47      @Test
48      public void testCustomMessage() throws Exception {
49          final String msgFileContainsTab =
50              "File contains tab characters (this is the first instance) :)";
51          final String[] expected = {
52              "14:25: " + msgFileContainsTab,
53          };
54          verifyWithInlineConfigParser(
55              getPath("InputFileTabCharacterCustomMessage.java"),
56              expected);
57      }
58  
59      @Test
60      public void testVerbose() throws Exception {
61          final String[] expected = {
62              "22:25: " + getCheckMessage(MSG_CONTAINS_TAB),
63              "148:35: " + getCheckMessage(MSG_CONTAINS_TAB),
64              "151:28: " + getCheckMessage(MSG_CONTAINS_TAB),
65              "159:9: " + getCheckMessage(MSG_CONTAINS_TAB),
66              "160:10: " + getCheckMessage(MSG_CONTAINS_TAB),
67              "161:1: " + getCheckMessage(MSG_CONTAINS_TAB),
68              "162:3: " + getCheckMessage(MSG_CONTAINS_TAB),
69              "163:3: " + getCheckMessage(MSG_CONTAINS_TAB),
70          };
71          verifyWithInlineConfigParser(
72                  getPath("InputFileTabCharacterSimple1.java"),
73              expected);
74      }
75  
76  }