KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > coding > RequireThisCheckTest


1 package com.puppycrawl.tools.checkstyle.checks.coding;
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 RequireThisCheckTest extends BaseCheckTestCase
9 {
10     public void testIt() throws Exception JavaDoc
11     {
12         final DefaultConfiguration checkConfig =
13             createCheckConfig(RequireThisCheck.class);
14         final String JavaDoc[] expected = {
15             "6:9: Reference to instance variable 'i' needs \"this.\".",
16             "12:9: Method call to 'method1' needs \"this.\".",
17             "26:9: Reference to instance variable 'i' needs \"this.\".",
18             "51:9: Reference to instance variable 'z' needs \"this.\".",
19 // "13:9: Unable find where 'j' is declared.",
20
};
21         verify(checkConfig,
22                getPath("coding" + File.separator + "InputRequireThis.java"),
23                expected);
24     }
25
26     public void testMethodsOnly() throws Exception JavaDoc
27     {
28         final DefaultConfiguration checkConfig =
29             createCheckConfig(RequireThisCheck.class);
30         checkConfig.addAttribute("checkFields", "false");
31         final String JavaDoc[] expected = {
32             "12:9: Method call to 'method1' needs \"this.\".",
33         };
34         verify(checkConfig,
35                getPath("coding" + File.separator + "InputRequireThis.java"),
36                expected);
37     }
38
39     public void testFieldsOnly() throws Exception JavaDoc
40     {
41         final DefaultConfiguration checkConfig =
42             createCheckConfig(RequireThisCheck.class);
43         checkConfig.addAttribute("checkMethods", "false");
44         final String JavaDoc[] expected = {
45             "6:9: Reference to instance variable 'i' needs \"this.\".",
46             "26:9: Reference to instance variable 'i' needs \"this.\".",
47             "51:9: Reference to instance variable 'z' needs \"this.\".",
48 // "13:9: Unable find where 'j' is declared.",
49
};
50         verify(checkConfig,
51                getPath("coding" + File.separator + "InputRequireThis.java"),
52                expected);
53     }
54
55     public void testGenerics() throws Exception JavaDoc
56     {
57         final DefaultConfiguration checkConfig =
58             createCheckConfig(RequireThisCheck.class);
59         final String JavaDoc[] expected = {};
60         verify(checkConfig, getPath("Input15Extensions.java"), expected);
61     }
62 }
63
Popular Tags