Skip to content

Commit 8fe1753

Browse files
committed
changes
1 parent 92623b1 commit 8fe1753

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
</dependency>
6666

6767
<!-- Test dependencies -->
68+
<dependency>
69+
<groupId>com.google.truth</groupId>
70+
<artifactId>truth</artifactId>
71+
<version>1.4.4</version>
72+
<scope>test</scope>
73+
</dependency>
6874
<dependency>
6975
<groupId>com.puppycrawl.tools</groupId>
7076
<artifactId>checkstyle</artifactId>

src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ protected void verify(String testCaseName) throws Exception {
6464
final Configuration config = getCheckConfigurations(inputPath);
6565
final List<CheckstyleViolation> violations = runCheckstyle(inputPath, config);
6666

67+
String[] expectedMessages = convertToExpectedMessages(violations);
68+
verifyWithInlineConfigParser(getPath(inputPath), expectedMessages);
69+
6770
final String beforeCode = readFile(getPath(inputPath));
6871
final String expectedAfterCode = readFile(getPath(outputPath));
6972

@@ -117,6 +120,18 @@ private void verifyOutputFile(String outputPath) throws Exception {
117120
}
118121
}
119122

123+
private String[] convertToExpectedMessages(List<CheckstyleViolation> violations) {
124+
return violations.stream()
125+
.map(v -> {
126+
if (v.getColumn() > 0) {
127+
return v.getLine() + ":" + v.getColumn() + ": " + v.getMessage();
128+
} else {
129+
return v.getLine() + ": " + v.getMessage();
130+
}
131+
})
132+
.toArray(String[]::new);
133+
}
134+
120135
private Configuration getCheckConfigurations(String inputPath) throws Exception {
121136
final String configFilePath = getPath(inputPath);
122137
final TestInputConfiguration testInputConfiguration =

src/test/resources/org/checkstyle/autofix/recipe/upperell/hexoctalliteral/InputHexOctalLiteral.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
package org.checkstyle.autofix.recipe.upperell.hexoctalliteral;
1515

1616
public class InputHexOctalLiteral {
17-
private long hexLower = 0x1ABCl;
18-
private long hexUpper = 0X2DEFl;
19-
private long octal = 0777l;
20-
private long binary = 0b1010l;
21-
private long decimal = 12345l;
17+
private long hexLower = 0x1ABCl; //violation
18+
private long hexUpper = 0X2DEFl; //violation
19+
private long octal = 0777l; //violation
20+
private long binary = 0b1010l; //violation
21+
private long decimal = 12345l; //violation
2222

2323
public void calculateValues() {
24+
//violation below
2425
long hexResult = 0xDEADBEEFl + 0xDEADBEFl; //suppressed violation for 0xDEADBEFl
26+
//violation below
2527
long octalResult = 01234l + 0xDEADBEEFl; //suppressed violation for 01234l
26-
long binaryResult = 0b11110000l;
28+
long binaryResult = 0b11110000l; //violation
2729
}
2830
}

0 commit comments

Comments
 (0)