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.modules;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.modules.ModuleDirectiveOrderCheck.MSG_GROUPING;
23  import static com.puppycrawl.tools.checkstyle.checks.modules.ModuleDirectiveOrderCheck.MSG_ORDER;
24  import static com.puppycrawl.tools.checkstyle.checks.modules.ModuleDirectiveOrderCheck.MSG_SEPARATED_INTERNALLY;
25  import static com.puppycrawl.tools.checkstyle.checks.modules.ModuleDirectiveOrderCheck.MSG_SEPARATION;
26  
27  import org.junit.jupiter.api.Test;
28  
29  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
30  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
31  
32  public class ModuleDirectiveOrderExamplesTest extends AbstractExamplesModuleTestSupport {
33  
34      @Override
35      public String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/modules/moduledirectiveorder";
37      }
38  
39      @Test
40      public void testExample1() throws Exception {
41          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
42  
43          verifyWithInlineConfigParser(getNonCompilablePath("Example1.java"), expected);
44      }
45  
46      @Test
47      public void testExample2() throws Exception {
48          final String[] expected = {
49              "18:3: " + getCheckMessage(MSG_ORDER, "uses", "exports"),
50          };
51  
52          verifyWithInlineConfigParser(getNonCompilablePath("Example2.java"), expected);
53      }
54  
55      @Test
56      public void testExample3() throws Exception {
57          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
58  
59          verifyWithInlineConfigParser(getNonCompilablePath("Example3.java"), expected);
60      }
61  
62      @Test
63      public void testUseCase1() throws Exception {
64          final String[] expected = {
65              "14:3: " + getCheckMessage(MSG_ORDER, "requires", "exports"),
66          };
67  
68          verifyWithInlineConfigParser(getNonCompilablePath("UseCase1.java"), expected);
69      }
70  
71      @Test
72      public void testUseCase2() throws Exception {
73          final String[] expected = {
74              "13:3: " + getCheckMessage(MSG_SEPARATION, "exports"),
75          };
76  
77          verifyWithInlineConfigParser(getNonCompilablePath("UseCase2.java"), expected);
78      }
79  
80      @Test
81      public void testUseCase3() throws Exception {
82          final String[] expected = {
83              "15:3: " + getCheckMessage(MSG_SEPARATION, "exports"),
84          };
85  
86          verifyWithInlineConfigParser(getNonCompilablePath("UseCase3.java"), expected);
87      }
88  
89      @Test
90      public void testUseCase4() throws Exception {
91          final String[] expected = {
92              "16:3: " + getCheckMessage(MSG_GROUPING, "requires"),
93          };
94  
95          verifyWithInlineConfigParser(getNonCompilablePath("UseCase4.java"), expected);
96      }
97  
98      @Test
99      public void testUseCase5() throws Exception {
100         final String[] expected = {
101             "14:3: " + getCheckMessage(MSG_SEPARATED_INTERNALLY, "requires"),
102         };
103 
104         verifyWithInlineConfigParser(getNonCompilablePath("UseCase5.java"), expected);
105     }
106 
107 }