diff --git a/pom.xml b/pom.xml
index 94d7ab6..647c9e5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,12 @@
+
+ com.google.truth
+ truth
+ 1.4.4
+ test
+
com.puppycrawl.tools
checkstyle
diff --git a/src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java b/src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java
index 3757cda..16aa100 100644
--- a/src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java
+++ b/src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java
@@ -57,7 +57,23 @@ protected String getPackageLocation() {
}
protected void verify(String testCaseName) throws Exception {
- verify(getCheckConfigurations(getInputFilePath(testCaseName)), testCaseName);
+
+ final String inputPath = getInputFilePath(testCaseName);
+ final String outputPath = getOutputFilePath(testCaseName);
+ final Configuration config = getCheckConfigurations(inputPath);
+ verifyOutputFile(outputPath, config);
+
+ final List violations = runCheckstyle(inputPath, config);
+
+ verifyWithInlineConfigParser(getPath(inputPath), convertToExpectedMessages(violations));
+
+ final String beforeCode = readFile(getPath(inputPath));
+ final String expectedAfterCode = readFile(getPath(outputPath));
+ final CheckConfiguration checkConfig = ConfigurationLoader.mapConfiguration(config);
+ final Recipe mainRecipe = createRecipe(violations, checkConfig);
+ testRecipe(beforeCode, expectedAfterCode,
+ getPath(inputPath), new InputClassRenamer(),
+ mainRecipe, new RemoveViolationComments());
}
protected void verify(Configuration config, String testCaseName) throws Exception {
@@ -74,8 +90,7 @@ protected void verify(Configuration config, String testCaseName) throws Exceptio
final CheckConfiguration checkConfig = ConfigurationLoader.mapConfiguration(config);
final Recipe mainRecipe = createRecipe(violations, checkConfig);
testRecipe(beforeCode, expectedAfterCode,
- getPath(inputPath), new InputClassRenamer(),
- new RemoveViolationComments(), mainRecipe);
+ getPath(inputPath), new InputClassRenamer(), mainRecipe);
}
private List runCheckstyle(String inputPath,
@@ -120,6 +135,17 @@ private void verifyOutputFile(String outputPath, Configuration config) throws Ex
}
}
+ private String[] convertToExpectedMessages(List violations) {
+ return violations.stream()
+ .map(violation -> {
+ final String message;
+ message = violation.getLine() + ":"
+ + violation.getColumn() + ": " + violation.getMessage();
+ return message;
+ })
+ .toArray(String[]::new);
+ }
+
private Configuration getCheckConfigurations(String inputPath) throws Exception {
final String configFilePath = getPath(inputPath);
final TestInputConfiguration testInputConfiguration =
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/InputComplexLongLiterals.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/InputComplexLongLiterals.java
index 09573a1..942accd 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/InputComplexLongLiterals.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/InputComplexLongLiterals.java
@@ -15,47 +15,49 @@
package org.checkstyle.autofix.recipe.upperell.complexlongliterals;
public class InputComplexLongLiterals {
- private long withUnderscores = 1_000_000l;
- private long multipleUnderscores = 1_234_567_890l;
+ private long withUnderscores = 1_000_000l; // violation 'Should use uppercase 'L'.'
+ private long multipleUnderscores = 1_234_567_890l; // violation 'Should use uppercase 'L'.'
- private long maxLong = 9223372036854775807l; //suppressed violation
- private long minLong = -9223372036854775808l; //suppressed violation
+ private long maxLong = 9223372036854775807l; // suppressed violation
+ private long minLong = -9223372036854775808l; // suppressed violation
private Long nullLong = null;
- private Long simpleLong = 1234l;
- private Long negativeLong = -5678l;
- private Long underscoreLong = 1_000_000l;
- Long maxLongObject = 9223372036854775807l; //suppressed violation
- Long minLongObject = -9223372036854775808l; //suppressed violation
+ private Long simpleLong = 1234l; // violation 'Should use uppercase 'L'.'
+ private Long negativeLong = -5678l; // violation 'Should use uppercase 'L'.'
+ private Long underscoreLong = 1_000_000l; // violation 'Should use uppercase 'L'.'
+ Long maxLongObject = 9223372036854775807l; // suppressed violation
+ Long minLongObject = -9223372036854775808l; // suppressed violation
public long calculate(long input1, long input2) {
- return input1 + input2 + 1000l;
+ return input1 + input2 + 1000l; // violation 'Should use uppercase 'L'.'
}
public void lambdaUsage() {
+ // violation below, 'Should use uppercase 'L'.'
java.util.function.LongSupplier supplier = () -> 42l;
+ // 3 violations below
java.util.Arrays.asList(1l, 2l, 3l).forEach(System.out::println);
}
public java.util.List getNumbers() {
- return java.util.Arrays.asList(100l, 200l, 300l);
+ return java.util.Arrays.asList(100l, 200l, 300l); // 3 violations
}
public void longObjectOperations() {
Long a = null;
- Long b = 1234l;
- Long c = Long.valueOf(5678l);
- Long d = new Long(9999l);
+ Long b = 1234l; // violation 'Should use uppercase 'L'.'
+ Long c = Long.valueOf(5678l); // violation 'Should use uppercase 'L'.'
+ Long d = new Long(9999l); // violation 'Should use uppercase 'L'.'
- Long conditional = (a != null) ? a : 0l;
- long primitive = b != null ? b : 0l;
- Long boxed = primitive + 1000l;
+ Long conditional = (a != null) ? a : 0l; // violation 'Should use uppercase 'L'.'
+ long primitive = b != null ? b : 0l; // violation 'Should use uppercase 'L'.'
+ Long boxed = primitive + 1000l; // violation 'Should use uppercase 'L'.'
}
public Long methodReturningLong(Long param) {
if (param == null) {
- return 12345l;
+ return 12345l; // violation 'Should use uppercase 'L'.'
}
- return param + 6789l;
+ return param + 6789l; // violation 'Should use uppercase 'L'.'
}
}
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/OutputComplexLongLiterals.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/OutputComplexLongLiterals.java
index 5443392..305177d 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/OutputComplexLongLiterals.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/OutputComplexLongLiterals.java
@@ -18,15 +18,15 @@ public class OutputComplexLongLiterals {
private long withUnderscores = 1_000_000L;
private long multipleUnderscores = 1_234_567_890L;
- private long maxLong = 9223372036854775807l; //suppressed violation
- private long minLong = -9223372036854775808l; //suppressed violation
+ private long maxLong = 9223372036854775807l; // suppressed violation
+ private long minLong = -9223372036854775808l; // suppressed violation
private Long nullLong = null;
private Long simpleLong = 1234L;
private Long negativeLong = -5678L;
private Long underscoreLong = 1_000_000L;
- Long maxLongObject = 9223372036854775807l; //suppressed violation
- Long minLongObject = -9223372036854775808l; //suppressed violation
+ Long maxLongObject = 9223372036854775807l; // suppressed violation
+ Long minLongObject = -9223372036854775808l; // suppressed violation
public long calculate(long input1, long input2) {
return input1 + input2 + 1000L;
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/hexoctalliteral/InputHexOctalLiteral.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/hexoctalliteral/InputHexOctalLiteral.java
index 1af3198..99ead15 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/hexoctalliteral/InputHexOctalLiteral.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/hexoctalliteral/InputHexOctalLiteral.java
@@ -14,15 +14,17 @@
package org.checkstyle.autofix.recipe.upperell.hexoctalliteral;
public class InputHexOctalLiteral {
- private long hexLower = 0x1ABCl;
- private long hexUpper = 0X2DEFl;
- private long octal = 0777l;
- private long binary = 0b1010l;
- private long decimal = 12345l;
+ private long hexLower = 0x1ABCl; // violation 'Should use uppercase 'L'.'
+ private long hexUpper = 0X2DEFl; // violation 'Should use uppercase 'L'.'
+ private long octal = 0777l; // violation 'Should use uppercase 'L'.'
+ private long binary = 0b1010l; // violation 'Should use uppercase 'L'.'
+ private long decimal = 12345l; // violation 'Should use uppercase 'L'.'
public void calculateValues() {
+ // violation below, 'Should use uppercase 'L'.'
long hexResult = 0xDEADBEEFl + 0xDEADBEFl; //suppressed violation for 0xDEADBEFl
+ // violation below, 'Should use uppercase 'L'.'
long octalResult = 01234l + 0xDEADBEEFl; //suppressed violation for 01234l
- long binaryResult = 0b11110000l;
+ long binaryResult = 0b11110000l; // violation 'Should use uppercase 'L'.'
}
}
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/InputStringAndComments.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/InputStringAndComments.java
index 8ad1a22..66c21df 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/InputStringAndComments.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/InputStringAndComments.java
@@ -16,14 +16,13 @@ public class InputStringAndComments {
private String message = "The value 456l should not change in strings";
private String code = "long value = 789l;"; // This 789l in string should not change
- // Only this actual long literal should change
- private long actualLong = 999l;
+ private long actualLong = 999l; // violation 'Should use uppercase 'L'.'
/*
* Multi-line comment with 111l should not change
*/
public void method() {
// Single line comment with 222l should not change
- long value = 333l; // This should change
+ long value = 333l; // violation 'Should use uppercase 'L'.'
}
}
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/OutputStringAndComments.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/OutputStringAndComments.java
index bdf6e48..fd6e161 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/OutputStringAndComments.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/stringandcomments/OutputStringAndComments.java
@@ -16,7 +16,6 @@ public class OutputStringAndComments {
private String message = "The value 456l should not change in strings";
private String code = "long value = 789l;"; // This 789l in string should not change
- // Only this actual long literal should change
private long actualLong = 999L;
/*
@@ -24,6 +23,6 @@ public class OutputStringAndComments {
*/
public void method() {
// Single line comment with 222l should not change
- long value = 333L; // This should change
+ long value = 333L;
}
}
diff --git a/src/test/resources/org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java b/src/test/resources/org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java
index 905d924..c4280c1 100644
--- a/src/test/resources/org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java
+++ b/src/test/resources/org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java
@@ -10,9 +10,9 @@
package org.checkstyle.autofix.recipe.upperell.symbolicliterals;
public class InputSymbolicLiterals {
- private long minLong = -9223372036854775808l;
- private Long negativeLong = -5678l;
- long a = -0xAl;
- long b = +-12l;
- long c = +-(-(-(-4l)));;
+ private long minLong = -9223372036854775808l; // violation 'Should use uppercase 'L'.'
+ private Long negativeLong = -5678l; // violation 'Should use uppercase 'L'.'
+ long a = -0xAl; // violation 'Should use uppercase 'L'.'
+ long b = +-12l; // violation 'Should use uppercase 'L'.'
+ long c = +-(-(-(-4l)));; // violation 'Should use uppercase 'L'.'
}