Skip to content

Commit 4893495

Browse files
Use xmlunit-legacy instead of xmlunit (#386)
* Use xmlunit-legacy instead of xmlunit - xmlunit is not compatible with JUnit5 hence we need to migrate it Signed-off-by: Peter Puškár <[email protected]> * Add license header Signed-off-by: Peter Puškár <[email protected]> * Remove unneeded dependency Signed-off-by: Peter Puškár <[email protected]> * Adopt newVersion 2.x for xmlunit --------- Signed-off-by: Peter Puškár <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent 79690a9 commit 4893495

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

src/main/resources/META-INF/rewrite/junit5.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ recipeList:
8787
- org.openrewrite.java.testing.junit5.AddMissingNested
8888
- org.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed
8989
- org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer
90+
- org.openrewrite.java.testing.junit5.UseXMLUnitLegacy
9091
- org.openrewrite.java.dependencies.RemoveDependency:
9192
groupId: junit
9293
artifactId: junit
@@ -266,3 +267,20 @@ recipeList:
266267
- org.openrewrite.java.testing.cleanup.AssertEqualsNullToAssertNull
267268
- org.openrewrite.java.testing.cleanup.AssertFalseNullToAssertNotNull
268269
- org.openrewrite.java.testing.cleanup.AssertionsArgumentOrder
270+
---
271+
type: specs.openrewrite.org/v1beta/recipe
272+
name: org.openrewrite.java.testing.junit5.UseXMLUnitLegacy
273+
displayName: Use XMLUnit Legacy for JUnit 5
274+
description: Migrates XMLUnit 1.x to XMLUnit legacy 2.x
275+
tags:
276+
- testing
277+
- junit
278+
- xmlunit
279+
recipeList:
280+
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
281+
oldGroupId: xmlunit
282+
oldArtifactId: xmlunit
283+
newGroupId: org.xmlunit
284+
newArtifactId: xmlunit-legacy
285+
newVersion: 2.x
286+
---
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.testing.junit5;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.InMemoryExecutionContext;
20+
import org.openrewrite.config.Environment;
21+
import org.openrewrite.java.JavaParser;
22+
import org.openrewrite.test.RecipeSpec;
23+
import org.openrewrite.test.RewriteTest;
24+
25+
import static org.openrewrite.java.Assertions.mavenProject;
26+
import static org.openrewrite.maven.Assertions.pomXml;
27+
28+
public class UseXMLUnitLegacyTest implements RewriteTest {
29+
@Override
30+
public void defaults(RecipeSpec spec) {
31+
spec
32+
.recipe(Environment.builder()
33+
.scanRuntimeClasspath()
34+
.build()
35+
.activateRecipes("org.openrewrite.java.testing.junit5.UseXMLUnitLegacy"));
36+
}
37+
38+
@Test
39+
void shouldMigrateMavenDependency() {
40+
rewriteRun(
41+
mavenProject("project",
42+
//language=xml
43+
pomXml(
44+
"""
45+
<project>
46+
<modelVersion>4.0.0</modelVersion>
47+
<groupId>com.example</groupId>
48+
<artifactId>demo</artifactId>
49+
<version>0.0.1-SNAPSHOT</version>
50+
<dependencies>
51+
<dependency>
52+
<groupId>xmlunit</groupId>
53+
<artifactId>xmlunit</artifactId>
54+
<version>1.6</version>
55+
</dependency>
56+
</dependencies>
57+
</project>
58+
""",
59+
"""
60+
<project>
61+
<modelVersion>4.0.0</modelVersion>
62+
<groupId>com.example</groupId>
63+
<artifactId>demo</artifactId>
64+
<version>0.0.1-SNAPSHOT</version>
65+
<dependencies>
66+
<dependency>
67+
<groupId>org.xmlunit</groupId>
68+
<artifactId>xmlunit-legacy</artifactId>
69+
<version>2.9.1</version>
70+
</dependency>
71+
</dependencies>
72+
</project>
73+
"""
74+
)
75+
)
76+
);
77+
}
78+
}

0 commit comments

Comments
 (0)