Skip to content

Commit 964e677

Browse files
committed
Fix JUnit assertion argument order before AssertJ migration
Fixes #492
1 parent 66c9a80 commit 964e677

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ tags:
346346
- testing
347347
- assertj
348348
recipeList:
349+
# First improve the assertions for JUnit, to fix inverted expected/actual values
350+
- org.openrewrite.java.testing.junit5.CleanupAssertions
349351
- org.openrewrite.java.testing.assertj.JUnitAssertArrayEqualsToAssertThat
350352
- org.openrewrite.java.testing.assertj.JUnitAssertEqualsToAssertThat
351353
- org.openrewrite.java.testing.assertj.JUnitAssertFalseToAssertThat

src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class CleanupAssertionsTest implements RewriteTest {
3232
public void defaults(RecipeSpec spec) {
3333
spec
3434
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9"))
35-
.recipe(Environment.builder()
36-
.scanRuntimeClasspath("org.openrewrite.java.testing.junit5")
37-
.build()
38-
.activateRecipes("org.openrewrite.java.testing.junit5.CleanupAssertions"));
35+
.recipeFromResources("org.openrewrite.java.testing.junit5.CleanupAssertions");
3936
}
4037

4138
@DocumentExample
@@ -130,4 +127,43 @@ void test() {
130127
)
131128
);
132129
}
130+
131+
@Test
132+
void assertNotEqualsInverted() {
133+
//language=java
134+
rewriteRun(
135+
java(
136+
"""
137+
import org.junit.jupiter.api.Assertions;
138+
import org.junit.jupiter.api.Test;
139+
140+
class A {
141+
class B {}
142+
143+
@Test
144+
public void FlippedParams(){
145+
B myVariable = new B();
146+
147+
Assertions.assertNotEquals(myVariable, null);
148+
}
149+
}
150+
""",
151+
"""
152+
import org.junit.jupiter.api.Assertions;
153+
import org.junit.jupiter.api.Test;
154+
155+
class A {
156+
class B {}
157+
158+
@Test
159+
public void FlippedParams(){
160+
B myVariable = new B();
161+
162+
Assertions.assertNotEquals(null, myVariable);
163+
}
164+
}
165+
"""
166+
)
167+
);
168+
}
133169
}

0 commit comments

Comments
 (0)