Skip to content

Commit 2e88428

Browse files
committed
Implemented Input Files based testing
1 parent 5bece85 commit 2e88428

File tree

10 files changed

+184
-23
lines changed

10 files changed

+184
-23
lines changed

config/import-control-test.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
<allow pkg="org.junit"/>
88
<allow pkg="org.openrewrite"/>
99
<allow pkg="org.checkstyle"/>
10-
</import-control>
10+
<allow pkg="java.io"/>
11+
<allow pkg="java.nio"/>
12+
</import-control>
Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,71 @@
11
package org.checkstyle.autofix.recipe;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
44
import static org.openrewrite.java.Assertions.java;
55

6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
610
import org.junit.jupiter.api.Test;
711
import org.openrewrite.test.RecipeSpec;
812
import org.openrewrite.test.RewriteTest;
913

1014
public class UpperEllRecipeTest implements RewriteTest {
1115

16+
private static final String BASE_TEST_RESOURCES_PATH = "src/test/resources/org"
17+
+ "/checkstyle/autofix/recipe/";
18+
1219
@Override
1320
public void defaults(RecipeSpec spec) {
1421
spec.recipe(new UpperEllRecipe());
1522
}
1623

1724
@Test
18-
void fixesLowercase() {
19-
rewriteRun(
20-
21-
java(
22-
"class Test {\n"
23-
+ " int value1 = 123l;\n"
24-
+ " long value2 = 0x123l;\n"
25-
+ " long value3 = 0123l;\n"
26-
+ " long value4 = 0b101l;\n"
27-
+ " String value5 = null;\n"
28-
+ "}\n",
29-
"class Test {\n"
30-
+ " int value1 = 123L;\n"
31-
+ " long value2 = 0x123L;\n"
32-
+ " long value3 = 0123L;\n"
33-
+ " long value4 = 0b101L;\n"
34-
+ " String value5 = null;\n"
35-
+ "}\n"
36-
)
37-
);
38-
assertTrue(true, "Test completed successfully");
25+
void longLiteralTest() throws IOException {
26+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
27+
+ "upperell/longliteral/InputLongLiteral.txt"));
28+
29+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
30+
+ "upperell/longliteral/OutputLongLiteral.txt"));
31+
32+
assertDoesNotThrow(() -> rewriteRun(java(beforeCode, afterCode)));
33+
}
34+
35+
@Test
36+
void hexOctalLiteralTest() throws IOException {
37+
38+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
39+
+ "upperell/hexoctalliteral/InputHexOctalLiteral.txt"));
40+
41+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
42+
+ "upperell/hexoctalliteral/OutputHexOctalLiteral.txt"));
43+
44+
assertDoesNotThrow(() -> rewriteRun(java(beforeCode, afterCode)));
3945
}
46+
47+
@Test
48+
void complexLongLiterals() throws IOException {
49+
50+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
51+
+ "upperell/complexlongliterals/InputComplexLongLiterals.txt"));
52+
53+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
54+
+ "upperell/complexlongliterals/OutputComplexLongLiterals.txt"));
55+
56+
assertDoesNotThrow(() -> rewriteRun(java(beforeCode, afterCode)));
57+
}
58+
59+
@Test
60+
void stringAndCommentTest() throws IOException {
61+
62+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
63+
+ "upperell/stringandcomments/InputStringAndComments.txt"));
64+
65+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
66+
+ "upperell/stringandcomments/OutputStringAndComments.txt"));
67+
68+
assertDoesNotThrow(() -> rewriteRun(java(beforeCode, afterCode)));
69+
}
70+
4071
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.checkstyle.autofix.recipe.upperell.complexlongliterals;
2+
3+
public class ComplexLongLiterals {
4+
private long withUnderscores = 1_000_000l;
5+
private long multipleUnderscores = 1_234_567_890l;
6+
7+
private long maxLong = 9223372036854775807l;
8+
private long minLong = -9223372036854775808l;
9+
10+
public long calculate(long input1, long input2) {
11+
return input1 + input2 + 1000l;
12+
}
13+
14+
public void lambdaUsage() {
15+
java.util.function.LongSupplier supplier = () -> 42l;
16+
java.util.Arrays.asList(1l, 2l, 3l).forEach(System.out::println);
17+
}
18+
19+
public java.util.List<Long> getNumbers() {
20+
return java.util.Arrays.asList(100l, 200l, 300l);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.checkstyle.autofix.recipe.upperell.complexlongliterals;
2+
3+
public class ComplexLongLiterals {
4+
private long withUnderscores = 1_000_000L;
5+
private long multipleUnderscores = 1_234_567_890L;
6+
7+
private long maxLong = 9223372036854775807L;
8+
private long minLong = -9223372036854775808L;
9+
10+
public long calculate(long input1, long input2) {
11+
return input1 + input2 + 1000L;
12+
}
13+
14+
public void lambdaUsage() {
15+
java.util.function.LongSupplier supplier = () -> 42L;
16+
java.util.Arrays.asList(1L, 2L, 3L).forEach(System.out::println);
17+
}
18+
19+
public java.util.List<Long> getNumbers() {
20+
return java.util.Arrays.asList(100L, 200L, 300L);
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.checkstyle.autofix.recipe.upperell.hexoctalliteral;
2+
3+
public class HexOctalLiteral {
4+
private long hexLower = 0x1ABCl;
5+
private long hexUpper = 0X2DEFl;
6+
private long octal = 0777l;
7+
private long binary = 0b1010l;
8+
9+
public void calculateValues() {
10+
long hexResult = 0xDEADBEEFl;
11+
long octalResult = 01234l;
12+
long binaryResult = 0b11110000l;
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.checkstyle.autofix.recipe.upperell.hexoctalliteral;
2+
3+
public class HexOctalLiteral {
4+
private long hexLower = 0x1ABCL;
5+
private long hexUpper = 0X2DEFL;
6+
private long octal = 0777L;
7+
private long binary = 0b1010L;
8+
9+
public void calculateValues() {
10+
long hexResult = 0xDEADBEEFL;
11+
long octalResult = 01234L;
12+
long binaryResult = 0b11110000L;
13+
}
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.checkstyle.autofix.recipe.upperell.longliteral;
2+
3+
public class LongLiteral {
4+
long decimal = 12345l;
5+
long hex = 0xABCDl;
6+
long octal = 511L;
7+
long binary = 0b1010l;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.checkstyle.autofix.recipe.upperell.longliteral;
2+
3+
public class LongLiteral {
4+
long decimal = 12345L;
5+
long hex = 0xABCDL;
6+
long octal = 511L;
7+
long binary = 0b1010L;
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.checkstyle.autofix.recipe.upperell.stringandcomments;
2+
3+
public class StringAndComments {
4+
/**
5+
* This comment mentions 123l but should not change
6+
*/
7+
private String message = "The value 456l should not change in strings";
8+
private String code = "long value = 789l;"; // This 789l in string should not change
9+
10+
// Only this actual long literal should change
11+
private long actualLong = 999l;
12+
13+
/*
14+
* Multi-line comment with 111l should not change
15+
*/
16+
public void method() {
17+
// Single line comment with 222l should not change
18+
long value = 333l; // This should change
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.checkstyle.autofix.recipe.upperell.stringandcomments;
2+
3+
public class StringAndComments {
4+
/**
5+
* This comment mentions 123l but should not change
6+
*/
7+
private String message = "The value 456l should not change in strings";
8+
private String code = "long value = 789l;"; // This 789l in string should not change
9+
10+
// Only this actual long literal should change
11+
private long actualLong = 999L;
12+
13+
/*
14+
* Multi-line comment with 111l should not change
15+
*/
16+
public void method() {
17+
// Single line comment with 222l should not change
18+
long value = 333L; // This should change
19+
}
20+
}

0 commit comments

Comments
 (0)