Skip to content

Commit d867415

Browse files
sullistimtebeek
andauthored
cleanup UpgradeJackson_2_3Test (#48)
* cleanup UpgradeJackson_2_3Test * Simplify assertion * Further polish --------- Co-authored-by: Tim te Beek <tim@moderne.io>
1 parent 34028a6 commit d867415

File tree

1 file changed

+14
-57
lines changed

1 file changed

+14
-57
lines changed

src/test/java/org/openrewrite/java/jackson/UpgradeJackson_2_3Test.java

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.DocumentExample;
20-
import org.openrewrite.config.Environment;
2120
import org.openrewrite.java.JavaParser;
2221
import org.openrewrite.test.RecipeSpec;
2322
import org.openrewrite.test.RewriteTest;
@@ -35,11 +34,7 @@ public void defaults(RecipeSpec spec) {
3534
spec
3635
.parser(JavaParser.fromJavaVersion().classpath(
3736
"jackson-annotations", "jackson-core", "jackson-databind"))
38-
.recipe(Environment.builder()
39-
.scanRuntimeClasspath("org.openrewrite")
40-
.build()
41-
.activateRecipes("org.openrewrite.java.jackson.UpgradeJackson_2_3")
42-
);
37+
.recipeFromResources("org.openrewrite.java.jackson.UpgradeJackson_2_3");
4338
}
4439

4540
@DocumentExample
@@ -89,7 +84,7 @@ void jacksonUpgradeToVersion3() {
8984
</project>
9085
""",
9186
spec -> spec.after(pom -> {
92-
Matcher versionMatcher = Pattern.compile("3\\.\\d+\\.\\d+(-rc[\\d]*)?").matcher(pom);
87+
Matcher versionMatcher = Pattern.compile("3\\.\\d+\\.\\d+").matcher(pom);
9388
assertThat(versionMatcher.find()).describedAs("Expected 3.0.x in %s", pom).isTrue();
9489
String jacksonVersion = versionMatcher.group(0);
9590

@@ -183,30 +178,10 @@ void jacksonUpgradeToVersion3_jacksonBomOnly() {
183178
</dependencyManagement>
184179
</project>
185180
""",
186-
spec -> spec.after(pom -> {
187-
Matcher versionMatcher = Pattern.compile("3\\.\\d+\\.\\d+(-rc[\\d]*)?").matcher(pom);
188-
assertThat(versionMatcher.find()).describedAs("Expected 3.0.x in %s", pom).isTrue();
189-
String jacksonVersion = versionMatcher.group(0);
190-
return """
191-
<project>
192-
<modelVersion>4.0.0</modelVersion>
193-
<groupId>org.example</groupId>
194-
<artifactId>example</artifactId>
195-
<version>1.0.0</version>
196-
<dependencyManagement>
197-
<dependencies>
198-
<dependency>
199-
<groupId>tools.jackson</groupId>
200-
<artifactId>jackson-bom</artifactId>
201-
<version>%s</version>
202-
<scope>pom</scope>
203-
<type>import</type>
204-
</dependency>
205-
</dependencies>
206-
</dependencyManagement>
207-
</project>
208-
""".formatted(jacksonVersion);
209-
})),
181+
spec -> spec.after(pom -> assertThat(pom)
182+
.contains("<groupId>tools.jackson</groupId>")
183+
.containsPattern("3\\.\\d+\\.\\d+")
184+
.actual())),
210185
//language=java
211186
java(
212187
"""
@@ -250,8 +225,8 @@ static void helloJackson() {
250225
@Test
251226
void jacksonUpgradeToVersion3_java8Only() {
252227
rewriteRun(
253-
//language=xml
254228
pomXml(
229+
//language=xml
255230
"""
256231
<project>
257232
<modelVersion>4.0.0</modelVersion>
@@ -277,31 +252,13 @@ void jacksonUpgradeToVersion3_java8Only() {
277252
</dependencies>
278253
</project>
279254
""",
280-
spec -> spec.after(pom -> {
281-
Matcher versionMatcher = Pattern.compile("3\\.\\d+\\.\\d+(-rc[\\d]*)?").matcher(pom);
282-
assertThat(versionMatcher.find()).describedAs("Expected 3.0.x in %s", pom).isTrue();
283-
String jacksonVersion = versionMatcher.group(0);
284-
285-
Matcher annotationsVersionMatcher = Pattern.compile("3\\.\\d+(\\.\\d+)*(-rc[\\d]*)?").matcher(pom);
286-
assertThat(annotationsVersionMatcher.find()).describedAs("Expected 3.x in %s", pom).isTrue();
287-
String annotationsVersion = annotationsVersionMatcher.group(0);
288-
289-
return """
290-
<project>
291-
<modelVersion>4.0.0</modelVersion>
292-
<groupId>org.example</groupId>
293-
<artifactId>example</artifactId>
294-
<version>1.0.0</version>
295-
<dependencies>
296-
<dependency>
297-
<groupId>tools.jackson.core</groupId>
298-
<artifactId>jackson-databind</artifactId>
299-
<version>%s</version>
300-
</dependency>
301-
</dependencies>
302-
</project>
303-
""".formatted(annotationsVersion);
304-
}))
255+
spec -> spec.after(pom -> assertThat(pom)
256+
.containsOnlyOnce("<dependency>")
257+
.contains(
258+
"<groupId>tools.jackson.core</groupId>",
259+
"<artifactId>jackson-databind</artifactId>")
260+
.containsPattern("3\\.\\d+\\.\\d+")
261+
.actual()))
305262
);
306263
}
307264

0 commit comments

Comments
 (0)