openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
68 stars 60 forks source link

Add recipe to transform assertEquals(a, null) to assertNull(a) #200

Closed yeikel closed 2 years ago

yeikel commented 2 years ago

This could be a good transformation to add :

assertEquals(a, null)

Could be replaced with assertNull(a)

Example :

@Test
void myTest(){

String a = null;
assertEquals(a, null);

}
@Test
void myTest(){

String a = null;
assertNull(a);
}
jkschneider commented 2 years ago

Good idea!

yeikel commented 2 years ago

Good idea!

Thank you for the quick turnaround!

jkschneider commented 2 years ago

In open source code we have already, found a few occurrences of this. https://app.moderne.io/recipes/org.openrewrite.java.testing.cleanup.AssertEqualsNullToAssertNull

image
yeikel commented 2 years ago

In open source code we have already, found a few occurrences of this. https://app.moderne.io/recipes/org.openrewrite.java.testing.cleanup.AssertEqualsNullToAssertNull

image

That's awesome. Thank you for sharing about it

I have seen this within my projects as well and I am looking forward to test it

yeikel commented 2 years ago

@jkschneider I forgot to mention it with the original issue, but the same applies to assertNotNull. I can create a separate issue if you prefer that

@Test
void myTest(){

String a = null;
assertNotEquals(a, null);

}

@Test
void myTest(){

String a = null;
assertNotNull(a);
}