KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > imports > ImportOrderCheckTest


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