Skip to content

Commit d4392fc

Browse files
Use flexible version assertions in ChangeDependencyGroupIdAndArtifactId tests (#6799)
* Use flexible version assertions in ChangeDependencyGroupIdAndArtifactIdTest Three tests were failing because they hardcoded version 2.21.0 for jackson-jakarta-rs-json-provider, but Maven Central now resolves 2.x to 2.21.1. Switch to using spec.after() with regex pattern matching to extract and validate the resolved version dynamically. * Simplify to assertThat(actual).containsPattern().actual() style Use the preferred fluent AssertJ pattern that combines groupId, artifactId and version assertions into a single containsPattern call. --------- Co-authored-by: Tim te Beek <tim@moderne.io>
1 parent 0225666 commit d4392fc

1 file changed

Lines changed: 13 additions & 81 deletions

File tree

rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openrewrite.test.RewriteTest;
2323
import org.openrewrite.test.SourceSpec;
2424

25+
import static org.assertj.core.api.Assertions.assertThat;
2526
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2627
import static org.openrewrite.java.Assertions.mavenProject;
2728
import static org.openrewrite.maven.Assertions.pomXml;
@@ -3329,33 +3330,10 @@ void versionNotDroppedWhenDependencyExcludedByOtherDependency() {
33293330
</dependencies>
33303331
</project>
33313332
""",
3332-
"""
3333-
<project>
3334-
<modelVersion>4.0.0</modelVersion>
3335-
<groupId>com.mycompany.app</groupId>
3336-
<artifactId>my-app</artifactId>
3337-
<version>1</version>
3338-
<dependencies>
3339-
<dependency>
3340-
<groupId>io.swagger.core.v3</groupId>
3341-
<artifactId>swagger-jaxrs2</artifactId>
3342-
<version>2.2.20</version>
3343-
<scope>provided</scope>
3344-
<exclusions>
3345-
<exclusion>
3346-
<groupId>com.fasterxml.jackson.jaxrs</groupId>
3347-
<artifactId>*</artifactId>
3348-
</exclusion>
3349-
</exclusions>
3350-
</dependency>
3351-
<dependency>
3352-
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
3353-
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
3354-
<version>2.21.0</version>
3355-
</dependency>
3356-
</dependencies>
3357-
</project>
3358-
"""
3333+
spec -> spec.after(actual -> assertThat(actual)
3334+
.containsPattern("<groupId>com\\.fasterxml\\.jackson\\.jakarta\\.rs</groupId>\\s*<artifactId>jackson-jakarta-rs-json-provider</artifactId>\\s*<version>2\\.\\d+\\.\\d+</version>")
3335+
.doesNotContain("<version>2.9.7</version>")
3336+
.actual())
33593337
)
33603338
);
33613339
}
@@ -3405,33 +3383,10 @@ void versionNotDroppedWhenTransitiveDependencyHasManagedVersion() {
34053383
</dependencies>
34063384
</project>
34073385
""",
3408-
"""
3409-
<project>
3410-
<modelVersion>4.0.0</modelVersion>
3411-
<groupId>com.mycompany.app</groupId>
3412-
<artifactId>my-app</artifactId>
3413-
<version>1</version>
3414-
<dependencies>
3415-
<dependency>
3416-
<groupId>io.swagger.core.v3</groupId>
3417-
<artifactId>swagger-jaxrs2-jakarta</artifactId>
3418-
<version>2.2.20</version>
3419-
<scope>provided</scope>
3420-
<exclusions>
3421-
<exclusion>
3422-
<groupId>com.fasterxml.jackson.jaxrs</groupId>
3423-
<artifactId>*</artifactId>
3424-
</exclusion>
3425-
</exclusions>
3426-
</dependency>
3427-
<dependency>
3428-
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
3429-
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
3430-
<version>2.21.1</version>
3431-
</dependency>
3432-
</dependencies>
3433-
</project>
3434-
"""
3386+
spec -> spec.after(actual -> assertThat(actual)
3387+
.containsPattern("<groupId>com\\.fasterxml\\.jackson\\.jakarta\\.rs</groupId>\\s*<artifactId>jackson-jakarta-rs-json-provider</artifactId>\\s*<version>2\\.\\d+\\.\\d+</version>")
3388+
.doesNotContain("<version>2.9.7</version>")
3389+
.actual())
34353390
)
34363391
);
34373392
}
@@ -3574,33 +3529,10 @@ void exclusionUpdatedWhenDependencyGroupIdChanges() {
35743529
</dependencies>
35753530
</project>
35763531
""",
3577-
"""
3578-
<project>
3579-
<modelVersion>4.0.0</modelVersion>
3580-
<groupId>com.mycompany.app</groupId>
3581-
<artifactId>my-app</artifactId>
3582-
<version>1</version>
3583-
<dependencies>
3584-
<dependency>
3585-
<groupId>io.swagger.core.v3</groupId>
3586-
<artifactId>swagger-jaxrs2-jakarta</artifactId>
3587-
<version>2.2.20</version>
3588-
<scope>provided</scope>
3589-
<exclusions>
3590-
<exclusion>
3591-
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
3592-
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
3593-
</exclusion>
3594-
</exclusions>
3595-
</dependency>
3596-
<dependency>
3597-
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
3598-
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
3599-
<version>2.21.0</version>
3600-
</dependency>
3601-
</dependencies>
3602-
</project>
3603-
"""
3532+
spec -> spec.after(actual -> assertThat(actual)
3533+
.containsPattern("<groupId>com\\.fasterxml\\.jackson\\.jakarta\\.rs</groupId>\\s*<artifactId>jackson-jakarta-rs-json-provider</artifactId>\\s*<version>2\\.\\d+\\.\\d+</version>")
3534+
.doesNotContain("<version>2.9.7</version>")
3535+
.actual())
36043536
)
36053537
);
36063538
}

0 commit comments

Comments
 (0)