KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > NewlineAtEndOfFileCheckTest


1 package com.puppycrawl.tools.checkstyle.checks;
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 com.puppycrawl.tools.checkstyle.api.Configuration;
7
8 public class NewlineAtEndOfFileCheckTest
9     extends BaseCheckTestCase
10 {
11     protected DefaultConfiguration createCheckerConfig(
12         Configuration aCheckConfig)
13     {
14         final DefaultConfiguration dc = new DefaultConfiguration("root");
15         dc.addChild(aCheckConfig);
16         return dc;
17     }
18
19     public void testNewlineAtEndOfFile()
20          throws Exception JavaDoc
21     {
22         final DefaultConfiguration checkConfig =
23             createCheckConfig(NewlineAtEndOfFileCheck.class);
24         checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF.toString());
25         final String JavaDoc[] expected = { };
26         verify(
27             createChecker(checkConfig),
28             getPath("InputNewlineAtEndOfFile.java"),
29             expected);
30     }
31
32     public void testNoNewlineAtEndOfFile()
33          throws Exception JavaDoc
34     {
35         final DefaultConfiguration checkConfig =
36             createCheckConfig(NewlineAtEndOfFileCheck.class);
37         checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF.toString());
38         final String JavaDoc[] expected = {
39             "0: File does not end with a newline."
40         };
41         verify(
42             createChecker(checkConfig),
43             getPath("InputNoNewlineAtEndOfFile.java"),
44             expected);
45     }
46     
47     public void testSetLineSeparatorFailure()
48         throws Exception JavaDoc
49     {
50         final DefaultConfiguration checkConfig =
51             createCheckConfig(NewlineAtEndOfFileCheck.class);
52         checkConfig.addAttribute("lineSeparator", "ct");
53         try {
54             createChecker(checkConfig);
55         }
56         catch (CheckstyleException ex) {
57             return;
58         }
59         fail("should throw conversion exception");
60     }
61     
62     public void testEmptyFileFile()
63          throws Exception JavaDoc
64     {
65         final DefaultConfiguration checkConfig =
66             createCheckConfig(NewlineAtEndOfFileCheck.class);
67         checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF.toString());
68         final String JavaDoc[] expected = {
69             "0: File does not end with a newline."
70         };
71         verify(
72             createChecker(checkConfig),
73             getPath("InputEmptyFile.txt"),
74             expected);
75     }
76 }
77
Popular Tags