Skip to content

Commit bd0de30

Browse files
arodionovLaurens-W
authored andcommitted
- reproducer RecipeRunStatsTest with non-correct source files count
1 parent f358c66 commit bd0de30

File tree

1 file changed

+66
-36
lines changed

1 file changed

+66
-36
lines changed

rewrite-core/src/test/java/org/openrewrite/table/RecipeRunStatsTest.java

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,59 @@
1919
import org.junit.jupiter.api.Test;
2020
import org.openrewrite.*;
2121
import org.openrewrite.marker.SearchResult;
22-
import org.openrewrite.test.RecipeSpec;
2322
import org.openrewrite.test.RewriteTest;
2423
import org.openrewrite.text.PlainText;
2524
import org.openrewrite.text.PlainTextVisitor;
2625

2726
import static org.assertj.core.api.Assertions.assertThat;
2827
import static org.openrewrite.test.SourceSpecs.text;
2928

30-
class RecipeRunStatsTest implements RewriteTest {
29+
@AllArgsConstructor
30+
class RecipeWithApplicabilityTest extends Recipe {
31+
@Override
32+
public String getDisplayName() {
33+
return "Recipe with an applicability test";
34+
}
3135

32-
@AllArgsConstructor
33-
static class RecipeWithApplicabilityTest extends Recipe {
34-
@Override
35-
public String getDisplayName() {
36-
return "Recipe with an applicability test";
37-
}
36+
@Override
37+
public String getDescription() {
38+
return "This recipe is a test utility which exists to exercise RecipeRunStats.";
39+
}
3840

39-
@Override
40-
public String getDescription() {
41-
return "This recipe is a test utility which exists to exercise RecipeRunStats.";
42-
}
41+
@Option(displayName = "New text", example = "txt")
42+
String newText;
4343

44-
@Override
45-
public TreeVisitor<?, ExecutionContext> getVisitor() {
46-
return Preconditions.check(
47-
new PlainTextVisitor<>() {
48-
@Override
49-
public PlainText visitText(PlainText text, ExecutionContext ctx) {
50-
if (!"sam".equals(text.getText())) {
51-
return SearchResult.found(text);
52-
}
53-
return text;
54-
}
55-
},
56-
new PlainTextVisitor<>() {
57-
@Override
58-
public PlainText visitText(PlainText tree, ExecutionContext ctx) {
59-
return tree.withText("sam");
44+
@Override
45+
public TreeVisitor<?, ExecutionContext> getVisitor() {
46+
return Preconditions.check(
47+
new PlainTextVisitor<>() {
48+
@Override
49+
public PlainText visitText(PlainText text, ExecutionContext ctx) {
50+
if (!"sam".equals(text.getText())) {
51+
return SearchResult.found(text);
6052
}
61-
});
62-
}
53+
return text;
54+
}
55+
},
56+
new PlainTextVisitor<>() {
57+
@Override
58+
public PlainText visitText(PlainText tree, ExecutionContext ctx) {
59+
return tree.withText(newText);
60+
}
61+
}
62+
);
6363
}
64+
}
6465

65-
@Override
66-
public void defaults(RecipeSpec spec) {
67-
spec.recipe(new RecipeWithApplicabilityTest());
68-
}
66+
class RecipeRunStatsTest implements RewriteTest {
6967

7068
@DocumentExample
7169
@Test
7270
void singleRow() {
7371
rewriteRun(
74-
spec -> spec.dataTable(RecipeRunStats.Row.class, rows -> {
72+
spec -> spec
73+
.recipe(new RecipeWithApplicabilityTest("sam"))
74+
.dataTable(RecipeRunStats.Row.class, rows -> {
7575
assertThat(rows)
7676
.as("Running a single recipe on a single source should produce a single row in the RecipeRunStats table")
7777
.hasSize(1);
@@ -89,4 +89,34 @@ void singleRow() {
8989
text("samuel", "sam")
9090
);
9191
}
92-
}
92+
93+
@Test
94+
void sourceFilesCountStatsForSameRecipe() {
95+
rewriteRun(
96+
spec -> spec
97+
.recipeFromYaml("""
98+
---
99+
type: specs.openrewrite.org/v1beta/recipe
100+
name: org.openrewrite.SeveralMethodNameChangeRecipes
101+
description: Test.
102+
recipeList:
103+
- org.openrewrite.table.RecipeWithApplicabilityTest:
104+
newText: sam1
105+
- org.openrewrite.table.RecipeWithApplicabilityTest:
106+
newText: sam2
107+
""",
108+
"org.openrewrite.SeveralMethodNameChangeRecipes")
109+
.dataTable(RecipeRunStats.Row.class, rows -> {
110+
assertThat(rows)
111+
.as("Running declarative recipe with parametrized recipe a single source should produce a two rows in the RecipeRunStats table")
112+
.hasSize(2);
113+
for (RecipeRunStats.Row row : rows) {
114+
assertThat(row.getSourceFiles())
115+
.as("If the same recipe runs with different parameters it shouldn't increment source files count")
116+
.isEqualTo(2);
117+
}
118+
}).expectedCyclesThatMakeChanges(2),
119+
text("sem", "sam2")
120+
);
121+
}
122+
}

0 commit comments

Comments
 (0)