KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.puppycrawl.tools.checkstyle.checks.imports;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
6 import java.io.File JavaDoc;
7
8 public class ImportControlCheckTest extends BaseCheckTestCase
9 {
10     public void testOne() throws Exception JavaDoc
11     {
12         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
13         checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
14                 + "/import-control_one.xml");
15         final String JavaDoc[] expected = {"5:1: Disallowed import - java.io.File."};
16
17         verify(checkConfig, getPath("imports" + File.separator
18                 + "InputImportControl.java"), expected);
19     }
20
21     public void testTwo() throws Exception JavaDoc
22     {
23         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
24         checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
25                 + "/import-control_two.xml");
26         final String JavaDoc[] expected = {"3:1: Disallowed import - java.awt.Image.",
27                 "4:1: Disallowed import - javax.swing.border.*.",
28                 "6:1: Disallowed import - java.awt.Button.ABORT."};
29
30         verify(checkConfig, getPath("imports" + File.separator
31                 + "InputImportControl.java"), expected);
32     }
33
34     public void testWrong() throws Exception JavaDoc
35     {
36         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
37         checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
38                 + "/import-control_wrong.xml");
39         final String JavaDoc[] expected = {"1:40: Import control file does not handle this package."};
40
41         verify(checkConfig, getPath("imports" + File.separator
42                 + "InputImportControl.java"), expected);
43     }
44
45     public void testMissing() throws Exception JavaDoc
46     {
47         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
48         final String JavaDoc[] expected = {"1:40: Missing an import control file."};
49         verify(checkConfig, getPath("imports" + File.separator
50                 + "InputImportControl.java"), expected);
51     }
52
53     public void testEmpty() throws Exception JavaDoc
54     {
55         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
56         checkConfig.addAttribute("file", " ");
57         final String JavaDoc[] expected = {"1:40: Missing an import control file."};
58         verify(checkConfig, getPath("imports" + File.separator
59                 + "InputImportControl.java"), expected);
60     }
61
62     public void testUnknown() throws Exception JavaDoc
63     {
64         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
65         checkConfig.addAttribute("file", "unknown-file");
66         final String JavaDoc[] expected = {};
67         try {
68             verify(checkConfig, getPath("imports" + File.separator
69                     + "InputImportControl.java"), expected);
70             fail("should fail");
71         }
72         catch (CheckstyleException ex) {
73             ;
74         }
75     }
76
77     public void testBroken() throws Exception JavaDoc
78     {
79         final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
80         checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
81                 + "/import-control_broken.xml");
82         final String JavaDoc[] expected = {};
83         try {
84             verify(checkConfig, getPath("imports" + File.separator
85                     + "InputImportControl.java"), expected);
86             fail("should fail");
87         }
88         catch (CheckstyleException ex) {
89             ;
90         }
91     }
92 }
93
Popular Tags