Skip to content

Commit b095953

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

File tree

6 files changed

+94
-20
lines changed

6 files changed

+94
-20
lines changed

config/import-control-test.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<allow pkg="org.junit"/>
88
<allow pkg="org.openrewrite"/>
99
<allow pkg="org.checkstyle"/>
10+
<allow pkg="java.io"/>
11+
<allow pkg="java.nio"/>
12+
1013
</import-control>

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

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,53 @@
33
import static org.junit.jupiter.api.Assertions.assertTrue;
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-
);
25+
void test1() throws IOException {
26+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
27+
+ "upperell/before/InputUpperEllTest.java"))
28+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
29+
30+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
31+
+ "upperell/after/InputUpperEllTest.java"))
32+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
33+
34+
rewriteRun(java(beforeCode, afterCode));
35+
36+
assertTrue(true, "Test completed successfully");
37+
}
38+
39+
@Test
40+
void test2() throws IOException {
41+
42+
final String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
43+
+ "upperell/before/InputUpperEllTest.java"))
44+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
45+
46+
final String afterCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
47+
+ "upperell/after/InputUpperEllTest.java"))
48+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
49+
50+
rewriteRun(java(beforeCode, afterCode));
51+
3852
assertTrue(true, "Test completed successfully");
3953
}
54+
4055
}
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.after;
2+
3+
public class InputUpperEllTest {
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.after;
2+
3+
public class InputUpperEllTest2 {
4+
static final long MAX = 9223372036854775807L;
5+
6+
long calculate(int x) {
7+
return x * 1000L + 500L;
8+
}
9+
10+
void process() {
11+
long[] values = {10L, 20L, 30L};
12+
long sum = values[0] + values[1] * 2L;
13+
14+
if (sum > 100L) {
15+
System.out.println("Sum: " + (sum - 50L));
16+
}
17+
18+
long mixed = 123L + 456L + 789L;
19+
}
20+
}
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.before;
2+
3+
public class InputUpperEllTest {
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.before;
2+
3+
public class InputUpperEllTest2 {
4+
static final long MAX = 9223372036854775807l;
5+
6+
long calculate(int x) {
7+
return x * 1000l + 500l;
8+
}
9+
10+
void process() {
11+
long[] values = {10l, 20l, 30l};
12+
long sum = values[0] + values[1] * 2l;
13+
14+
if (sum > 100l) {
15+
System.out.println("Sum: " + (sum - 50l));
16+
}
17+
18+
long mixed = 123l + 456L + 789l;
19+
}
20+
}

0 commit comments

Comments
 (0)