KickJava   Java API By Example, From Geeks To Geeks.

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


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 MultipleStringLiteralsCheckTest extends BaseCheckTestCase
9 {
10     public void testIt() throws Exception JavaDoc
11     {
12         DefaultConfiguration checkConfig =
13             createCheckConfig(MultipleStringLiteralsCheck.class);
14         checkConfig.addAttribute("allowedDuplicates", "2");
15         checkConfig.addAttribute("ignoreStringsRegexp", "");
16
17         final String JavaDoc[] expected = {
18             "5:16: The String \"StringContents\" appears 3 times in the file.",
19             "8:17: The String \"\" appears 4 times in the file.",
20             "10:23: The String \", \" appears 3 times in the file.",
21             };
22
23         verify(checkConfig,
24                getPath("coding" + File.separator + "InputMultipleStringLiterals.java"),
25                expected);
26     }
27
28     public void testItIgnoreEmpty() throws Exception JavaDoc
29     {
30         DefaultConfiguration checkConfig =
31             createCheckConfig(MultipleStringLiteralsCheck.class);
32         checkConfig.addAttribute("allowedDuplicates", "2");
33
34         final String JavaDoc[] expected = {
35             "5:16: The String \"StringContents\" appears 3 times in the file.",
36             "10:23: The String \", \" appears 3 times in the file.",
37         };
38
39         verify(checkConfig,
40                getPath("coding" + File.separator + "InputMultipleStringLiterals.java"),
41                expected);
42     }
43
44     public void testItIgnoreEmptyAndComaSpace() throws Exception JavaDoc
45     {
46         DefaultConfiguration checkConfig =
47             createCheckConfig(MultipleStringLiteralsCheck.class);
48         checkConfig.addAttribute("allowedDuplicates", "2");
49         checkConfig.addAttribute("ignoreStringsRegexp", "^((\"\")|(\", \"))$");
50
51         final String JavaDoc[] expected = {
52             "5:16: The String \"StringContents\" appears 3 times in the file.",
53         };
54
55         verify(checkConfig,
56                getPath("coding" + File.separator + "InputMultipleStringLiterals.java"),
57                expected);
58     }
59 }
60
Popular Tags