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.imports;
21
22 import static com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.MSG_ORDERING;
23 import static com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.MSG_SEPARATED_IN_GROUP;
24 import static com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.MSG_SEPARATION;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
29
30 public class ImportOrderCheckExamplesTest extends AbstractExamplesModuleTestSupport {
31 @Override
32 protected String getPackageLocation() {
33 return "com/puppycrawl/tools/checkstyle/checks/imports/importorder";
34 }
35
36 @Test
37 public void testExample1() throws Exception {
38 final String[] expected = {
39 "15:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.io.IOException"),
40 "15:1: " + getCheckMessage(MSG_ORDERING, "java.io.IOException"),
41 "19:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "javax.net.ssl.TrustManager"),
42 "22:1: " + getCheckMessage(MSG_ORDERING, "java.util.Set"),
43 "23:1: " + getCheckMessage(MSG_ORDERING, "com.neurologic.http.HttpClient"),
44 };
45
46 verifyWithInlineConfigParser(getNonCompilablePath("Example1.java"), expected);
47 }
48
49 @Test
50 public void testExample2() throws Exception {
51 final String[] expected = {
52 "19:1: " + getCheckMessage(MSG_ORDERING, "java.lang.Math"),
53 "22:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.net.URL"),
54 "27:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "javax.net.ssl.X509TrustManager"),
55 };
56
57 verifyWithInlineConfigParser(getNonCompilablePath("Example2.java"), expected);
58 }
59
60 @Test
61 public void testExample3() throws Exception {
62 final String[] expected = {
63 "21:1: " + getCheckMessage(MSG_ORDERING, "java.io.File"),
64 "23:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.io.IOException"),
65 "27:1: " + getCheckMessage(MSG_ORDERING, "javax.WindowConstants.*"),
66 "29:1: " + getCheckMessage(MSG_SEPARATION, "org.apache.http.ClientConnectionManager"),
67 };
68
69 verifyWithInlineConfigParser(getNonCompilablePath("Example3.java"), expected);
70 }
71
72 @Test
73 public void testExample4() throws Exception {
74 final String[] expected = {
75 "24:1: " + getCheckMessage(MSG_ORDERING, "javax.swing.JComponent"),
76 "27:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.net.URL"),
77 "29:1: " + getCheckMessage(MSG_ORDERING, "javax.swing.JComponent"),
78 "30:1: " + getCheckMessage(MSG_ORDERING, "com.neurologic.http.HttpClient"),
79 };
80
81 verifyWithInlineConfigParser(getNonCompilablePath("Example4.java"), expected);
82 }
83
84 @Test
85 public void testExample5() throws Exception {
86 final String[] expected = {
87 "17:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "javax.swing.JComponent"),
88 };
89
90 verifyWithInlineConfigParser(getNonCompilablePath("Example5.java"), expected);
91 }
92
93 @Test
94 public void testExample6() throws Exception {
95 final String[] expected = {
96 "19:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.util.Set"),
97 "20:1: " + getCheckMessage(MSG_ORDERING, "java.lang.Math.abs"),
98 };
99
100 verifyWithInlineConfigParser(getNonCompilablePath("Example6.java"), expected);
101 }
102
103 @Test
104 public void testExample7() throws Exception {
105 final String[] expected = {
106
107 };
108
109 verifyWithInlineConfigParser(getNonCompilablePath("Example7.java"), expected);
110 }
111
112 @Test
113 public void testExample8() throws Exception {
114 final String[] expected = {
115
116 };
117
118 verifyWithInlineConfigParser(getNonCompilablePath("Example8.java"), expected);
119 }
120
121 @Test
122 public void testExample9() throws Exception {
123 final String[] expected = {
124 "21:1: " + getCheckMessage(MSG_ORDERING,
125 "io.netty.handler.codec.http.HttpHeaders.Names.DATE"),
126 };
127
128 verifyWithInlineConfigParser(getNonCompilablePath("Example9.java"), expected);
129 }
130
131 @Test
132 public void testExample10() throws Exception {
133 final String[] expected = {
134 "18:1: " + getCheckMessage(MSG_SEPARATION, "javax.swing.JComponent"),
135 };
136
137 verifyWithInlineConfigParser(getNonCompilablePath("Example10.java"), expected);
138 }
139
140 @Test
141 public void testExample11() throws Exception {
142 final String[] expected = {
143
144 };
145
146 verifyWithInlineConfigParser(getNonCompilablePath("Example11.java"), expected);
147 }
148
149 @Test
150 public void testExample12() throws Exception {
151 final String[] expected = {
152 "17:1: " + getCheckMessage(MSG_ORDERING, "java.io.File.createTempFile"),
153 };
154
155 verifyWithInlineConfigParser(getNonCompilablePath("Example12.java"), expected);
156 }
157 }