1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.checks.imports;
21
22 import org.checkstyle.base.AbstractCheckstyleModuleTestSupport;
23 import org.junit.jupiter.api.Test;
24
25 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
26 import com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck;
27 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
28
29 public class ImportOrderTest extends AbstractCheckstyleModuleTestSupport {
30
31 @Override
32 protected String getPackageLocation() {
33 return "org/checkstyle/checks/imports/importorder";
34 }
35
36 @Test
37 public void testAndroid() throws Exception {
38 final DefaultConfiguration checkConfig = createModuleConfig(ImportOrderCheck.class);
39 checkConfig.addProperty("groups",
40 "android,androidx,com.android,dalvik,com,gov,junit,libcore,net,org,java,javax");
41 checkConfig.addProperty("option", "top");
42 checkConfig.addProperty("ordered", "true");
43 checkConfig.addProperty("separated", "true");
44 checkConfig.addProperty("separatedStaticGroups", "true");
45 checkConfig.addProperty("staticGroups",
46 "android,androidx,com.android,dalvik,com,gov,junit,libcore,net,org,java,javax");
47
48 final String filePath = getNonCompilablePath("InputFromAndroid.java");
49 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
50 final Integer[] warnList = getLinesWithWarn(filePath);
51 verify(checkConfig, filePath, expected, warnList);
52 }
53
54 @Test
55 public void testSpotify() throws Exception {
56 final DefaultConfiguration checkConfig = createModuleConfig(ImportOrderCheck.class);
57 checkConfig.addProperty("groups", "android,com,net,junit,org,java,javax");
58 checkConfig.addProperty("option", "bottom");
59 checkConfig.addProperty("ordered", "true");
60 checkConfig.addProperty("separated", "true");
61 checkConfig.addProperty("separatedStaticGroups", "true");
62 checkConfig.addProperty("staticGroups", "android,com,net,junit,org,java,javax");
63
64 final String filePath = getNonCompilablePath("InputFromSpotify.java");
65 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
66 final Integer[] warnList = getLinesWithWarn(filePath);
67 verify(checkConfig, filePath, expected, warnList);
68 }
69
70 @Test
71 public void testTwitter() throws Exception {
72 final DefaultConfiguration checkConfig = createModuleConfig(ImportOrderCheck.class);
73 checkConfig.addProperty("caseSensitive", "true");
74 checkConfig.addProperty("groups", "android,com.twitter,com,junit,net,org,java,javax");
75 checkConfig.addProperty("option", "bottom");
76 checkConfig.addProperty("ordered", "true");
77 checkConfig.addProperty("separated", "true");
78 checkConfig.addProperty("separatedStaticGroups", "true");
79 checkConfig.addProperty("staticGroups",
80 "android,com.twitter,com,junit,net,org,java,javax");
81
82 final String filePath = getNonCompilablePath("InputFromTwitter.java");
83 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
84 final Integer[] warnList = getLinesWithWarn(filePath);
85 verify(checkConfig, filePath, expected, warnList);
86 }
87
88 }