01: package com.puppycrawl.tools.checkstyle.checks.imports;
02:
03: import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
04: import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
05:
06: import java.io.File;
07:
08: public class ImportOrderCheckTest extends BaseCheckTestCase {
09: public void testDefault() throws Exception {
10: final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
11: final String[] expected = {
12: "3: Wrong order for 'java.awt.Dialog' import.",
13: "7: Wrong order for 'javax.swing.JComponent' import.",
14: "9: Wrong order for 'java.io.File' import.",
15: "11: Wrong order for 'java.io.IOException' import." };
16:
17: verify(checkConfig, getPath("imports" + File.separator
18: + "InputImportOrder.java"), expected);
19: }
20:
21: public void testGroups() throws Exception {
22: final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
23: checkConfig.addAttribute("groups",
24: "java.awt, javax.swing, java.io");
25: final String[] expected = {
26: "3: Wrong order for 'java.awt.Dialog' import.",
27: "11: Wrong order for 'java.io.IOException' import.",
28: "14: Wrong order for 'javax.swing.WindowConstants.*' import." };
29:
30: verify(checkConfig, getPath("imports" + File.separator
31: + "InputImportOrder.java"), expected);
32: }
33:
34: public void testSeparated() throws Exception {
35: final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
36: checkConfig.addAttribute("groups",
37: "java.awt, javax.swing, java.io");
38: checkConfig.addAttribute("separated", "true");
39: checkConfig.addAttribute("ordered", "false");
40: final String[] expected = {
41: "7: 'javax.swing.JComponent' should be separated from previous imports.",
42: "9: 'java.io.File' should be separated from previous imports.",
43: "14: Wrong order for 'javax.swing.WindowConstants.*' import." };
44:
45: verify(checkConfig, getPath("imports" + File.separator
46: + "InputImportOrder.java"), expected);
47: }
48:
49: public void testCaseInsensitive() throws Exception {
50: final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
51: checkConfig.addAttribute("caseSensitive", "false");
52: final String[] expected = {};
53:
54: verify(checkConfig, getPath("imports" + File.separator
55: + "InputImportOrderCaseInsensitive.java"), expected);
56: }
57: }
|