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, "java.util.Map"),
44 "24:1: " + getCheckMessage(MSG_ORDERING, "com.sun.security.auth.UserPrincipal"),
45 };
46
47 verifyWithInlineConfigParser(getPath("Example1.java"), expected);
48 }
49
50 @Test
51 public void testExample2() throws Exception {
52 final String[] expected = {
53 "19:1: " + getCheckMessage(MSG_ORDERING, "java.lang.Math.PI"),
54 "22:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.net.URL"),
55 "27:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "javax.net.ssl.X509TrustManager"),
56 };
57
58 verifyWithInlineConfigParser(getPath("Example2.java"), expected);
59 }
60
61 @Test
62 public void testExample3() throws Exception {
63 final String[] expected = {
64 "21:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.io.File"),
65 "23:1: " + getCheckMessage(MSG_SEPARATED_IN_GROUP, "java.io.IOException"),
66 "27:1: " + getCheckMessage(MSG_ORDERING, "javax.swing.WindowConstants.EXIT_ON_CLOSE"),
67 "29:1: " + getCheckMessage(MSG_SEPARATION, "org.w3c.dom.Element"),
68 };
69
70 verifyWithInlineConfigParser(getPath("Example3.java"), expected);
71 }
72
73 @Test
74 public void testExample4() throws Exception {
75 final String[] expected = {
76 "24:1: " + getCheckMessage(MSG_ORDERING, "javax.swing.JComponent"),
77 "27:1: " + getCheckMessage(MSG_ORDERING, "javax.swing.JComponent"),
78 "28:1: " + getCheckMessage(MSG_ORDERING, "com.sun.source.tree.Tree"),
79 };
80
81 verifyWithInlineConfigParser(getPath("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(getPath("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.sin"),
98 };
99
100 verifyWithInlineConfigParser(getPath("Example6.java"), expected);
101 }
102
103 @Test
104 public void testExample7() throws Exception {
105 final String[] expected = {
106
107 };
108
109 verifyWithInlineConfigParser(getPath("Example7.java"), expected);
110 }
111
112 @Test
113 public void testExample8() throws Exception {
114 final String[] expected = {
115
116 };
117
118 verifyWithInlineConfigParser(getPath("Example8.java"), expected);
119 }
120
121 @Test
122 public void testExample9() throws Exception {
123 final String[] expected = {
124 "21:1: " + getCheckMessage(MSG_ORDERING,
125 "java.lang.Character.UnicodeBlock.BASIC_LATIN"),
126 };
127
128 verifyWithInlineConfigParser(getPath("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.WindowConstants.*"),
135 };
136
137 verifyWithInlineConfigParser(getPath("Example10.java"), expected);
138 }
139
140 @Test
141 public void testExample11() throws Exception {
142 final String[] expected = {
143
144 };
145
146 verifyWithInlineConfigParser(getPath("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(getPath("Example12.java"), expected);
156 }
157 }