KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > sizes > FileLengthCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.sizes;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
6
7 public class FileLengthCheckTest
8     extends BaseCheckTestCase
9 {
10     private void runIt(String JavaDoc aMax, String JavaDoc[] aExpected) throws Exception JavaDoc
11     {
12         final DefaultConfiguration checkConfig =
13             createCheckConfig(FileLengthCheck.class);
14         checkConfig.addAttribute("max", aMax);
15         verify(checkConfig, getPath("InputSimple.java"), aExpected);
16     }
17
18     public void testAlarm() throws Exception JavaDoc
19     {
20         final String JavaDoc[] expected = {
21             "1: File length is 225 lines (max allowed is 20)."
22         };
23         runIt("20", expected);
24     }
25
26     public void testOK() throws Exception JavaDoc
27     {
28         final String JavaDoc[] expected = {
29         };
30         runIt("2000", expected);
31     }
32
33     public void testArgs() throws Exception JavaDoc
34     {
35         final DefaultConfiguration checkConfig =
36             createCheckConfig(FileLengthCheck.class);
37         try {
38             checkConfig.addAttribute("max", "abc");
39             createChecker(checkConfig);
40             fail("Should indicate illegal args");
41         }
42         catch (CheckstyleException ex)
43         {
44             // Expected Exception because of illegal argument for "max"
45
}
46     }
47
48
49 }
50
Popular Tags