Skip to content

Commit a4b5330

Browse files
committed
Implemented Input Files based testing
1 parent 9c20bb1 commit a4b5330

File tree

5 files changed

+93
-21
lines changed

5 files changed

+93
-21
lines changed

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

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77
import static org.junit.jupiter.api.Assertions.assertTrue;
88
import static org.openrewrite.java.Assertions.java;
99

10+
import java.io.IOException;
11+
import java.nio.file.Files;
12+
import java.nio.file.Paths;
13+
1014
public class UpperEllRecipeTest implements RewriteTest {
1115

1216
@Override
1317
public void defaults(RecipeSpec spec) {
1418
spec.recipe(new UpperEllRecipe());
1519
}
1620

21+
private static final String BASE_TEST_RESOURCES_PATH = "src/test/resources/org"
22+
+ "/checkstyle/autofix/recipe/";
23+
1724
@Test
18-
void fixesLowercaseLInLongLiteralsFromResources() {
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+
String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
27+
+ "upperell/before/InputUpperEllTest.java"))
28+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
29+
30+
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+
3836
assertTrue(true, "Test completed successfully");
3937
}
40-
}
38+
39+
@Test
40+
void test2() throws IOException {
41+
42+
String beforeCode = Files.readString(Paths.get(BASE_TEST_RESOURCES_PATH
43+
+ "upperell/before/InputUpperEllTest.java"))
44+
.replaceFirst("^\\s*package.*?;\\s*\\n?", "");
45+
46+
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+
52+
assertTrue(true, "Test completed successfully");
53+
}
54+
55+
56+
}
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)