1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.google.checkstyle.test.chapter4formatting.rule43onestatement;
21
22 import org.junit.jupiter.api.Test;
23
24 import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport;
25 import com.puppycrawl.tools.checkstyle.api.Configuration;
26 import com.puppycrawl.tools.checkstyle.checks.coding.OneStatementPerLineCheck;
27
28 public class OneStatementPerLineTest extends AbstractGoogleModuleTestSupport {
29
30 @Override
31 protected String getPackageLocation() {
32 return "com/google/checkstyle/test/chapter4formatting/rule43onestatement";
33 }
34
35 @Test
36 public void testOneStatement() throws Exception {
37 final String msg = getCheckMessage(OneStatementPerLineCheck.class,
38 "multiple.statements.line");
39
40 final String[] expected = {
41 "6:59: " + msg,
42 "50:21: " + msg,
43 "52:21: " + msg,
44 "54:42: " + msg,
45 "57:25: " + msg,
46 "58:35: " + msg,
47 "68:14: " + msg,
48 "95:25: " + msg,
49 "97:25: " + msg,
50 "99:46: " + msg,
51 "102:29: " + msg,
52 "103:39: " + msg,
53 "111:15: " + msg,
54 "123:23: " + msg,
55 "138:59: " + msg,
56 "170:19: " + msg,
57 "188:15: " + msg,
58 "196:15: " + msg,
59 "208:6: " + msg,
60 "217:22: " + msg,
61 "307:39: " + msg,
62 };
63
64 final Configuration checkConfig = getModuleConfig("OneStatementPerLine");
65 final String filePath = getPath("InputOneStatementPerLine.java");
66
67 final Integer[] warnList = getLinesWithWarn(filePath);
68 verify(checkConfig, filePath, expected, warnList);
69 }
70
71 @Test
72 public void testOneStatementNonCompilableInput() throws Exception {
73 final String msg = getCheckMessage(OneStatementPerLineCheck.class,
74 "multiple.statements.line");
75
76 final String[] expected = {
77 "32:6: " + msg,
78 "37:58: " + msg,
79 "38:58: " + msg,
80 "38:74: " + msg,
81 "39:50: " + msg,
82 "43:85: " + msg,
83 };
84
85 final Configuration checkConfig = getModuleConfig("OneStatementPerLine");
86 final String filePath = getNonCompilablePath("InputOneStatementPerLine.java");
87
88 final Integer[] warnList = getLinesWithWarn(filePath);
89 verify(checkConfig, filePath, expected, warnList);
90 }
91
92 }