Philzen / rewrite-TestNG-to-JUnit5

An OpenRewrite recipe to migrate your project from TestNG to JUnit 5 (Jupiter)
4 stars 0 forks source link

Implement migration of assertions #2

Open Philzen opened 5 months ago

Philzen commented 5 months ago

This is a complete list of the methods in org.testng.Assert:

assertEquals[boolean arg0, boolean arg1, java.lang.String arg2]
assertEquals[boolean arg0, boolean arg1]
assertEquals[boolean arg0, java.lang.Boolean arg1, java.lang.String arg2]
assertEquals[boolean arg0, java.lang.Boolean arg1]
assertEquals[boolean[] arg0, boolean[] arg1, java.lang.String arg2]
assertEquals[boolean[] arg0, boolean[] arg1]
assertEquals[byte arg0, byte arg1, java.lang.String arg2]
assertEquals[byte arg0, byte arg1]
assertEquals[byte arg0, java.lang.Byte arg1, java.lang.String arg2]
assertEquals[byte arg0, java.lang.Byte arg1]
assertEquals[byte[] arg0, byte[] arg1, java.lang.String arg2]
assertEquals[byte[] arg0, byte[] arg1]
assertEquals[char arg0, char arg1, java.lang.String arg2]
assertEquals[char arg0, char arg1]
assertEquals[char arg0, java.lang.Character arg1, java.lang.String arg2]
assertEquals[char arg0, java.lang.Character arg1]
assertEquals[char[] arg0, char[] arg1, java.lang.String arg2]
assertEquals[char[] arg0, char[] arg1]
assertEquals[double arg0, double arg1, double arg2, java.lang.String arg3]
assertEquals[double arg0, double arg1, double arg2]
assertEquals[double arg0, double arg1, java.lang.String arg2]
assertEquals[double arg0, double arg1]
assertEquals[double arg0, java.lang.Double arg1, java.lang.String arg2]
assertEquals[double arg0, java.lang.Double arg1]
assertEquals[double[] arg0, double[] arg1, double arg2, java.lang.String arg3]
assertEquals[double[] arg0, double[] arg1, double arg2]
assertEquals[double[] arg0, double[] arg1, java.lang.String arg2]
assertEquals[double[] arg0, double[] arg1]
assertEquals[float arg0, float arg1, float arg2, java.lang.String arg3]
assertEquals[float arg0, float arg1, float arg2]
assertEquals[float arg0, float arg1, java.lang.String arg2]
assertEquals[float arg0, float arg1]
assertEquals[float arg0, java.lang.Float arg1, java.lang.String arg2]
assertEquals[float arg0, java.lang.Float arg1]
assertEquals[float[] arg0, float[] arg1, float arg2, java.lang.String arg3]
assertEquals[float[] arg0, float[] arg1, float arg2]
assertEquals[float[] arg0, float[] arg1, java.lang.String arg2]
assertEquals[float[] arg0, float[] arg1]
assertEquals[int arg0, int arg1, java.lang.String arg2]
assertEquals[int arg0, int arg1]
assertEquals[int arg0, java.lang.Integer arg1, java.lang.String arg2]
assertEquals[int arg0, java.lang.Integer arg1]
assertEquals[int[] arg0, int[] arg1, java.lang.String arg2]
assertEquals[int[] arg0, int[] arg1]
assertEquals[java.lang.Boolean arg0, boolean arg1, java.lang.String arg2]
assertEquals[java.lang.Boolean arg0, boolean arg1]
assertEquals[java.lang.Boolean arg0, java.lang.Boolean arg1, java.lang.String arg2]
assertEquals[java.lang.Boolean arg0, java.lang.Boolean arg1]
assertEquals[java.lang.Byte arg0, byte arg1, java.lang.String arg2]
assertEquals[java.lang.Byte arg0, byte arg1]
assertEquals[java.lang.Byte arg0, java.lang.Byte arg1, java.lang.String arg2]
assertEquals[java.lang.Byte arg0, java.lang.Byte arg1]
assertEquals[java.lang.Character arg0, char arg1, java.lang.String arg2]
assertEquals[java.lang.Character arg0, char arg1]
assertEquals[java.lang.Character arg0, java.lang.Character arg1, java.lang.String arg2]
assertEquals[java.lang.Character arg0, java.lang.Character arg1]
assertEquals[java.lang.Double arg0, double arg1, java.lang.String arg2]
assertEquals[java.lang.Double arg0, double arg1]
assertEquals[java.lang.Double arg0, java.lang.Double arg1, java.lang.String arg2]
assertEquals[java.lang.Double arg0, java.lang.Double arg1]
assertEquals[java.lang.Float arg0, float arg1, java.lang.String arg2]
assertEquals[java.lang.Float arg0, float arg1]
assertEquals[java.lang.Float arg0, java.lang.Float arg1, java.lang.String arg2]
assertEquals[java.lang.Float arg0, java.lang.Float arg1]
assertEquals[java.lang.Integer arg0, int arg1, java.lang.String arg2]
assertEquals[java.lang.Integer arg0, int arg1]
assertEquals[java.lang.Integer arg0, java.lang.Integer arg1, java.lang.String arg2]
assertEquals[java.lang.Integer arg0, java.lang.Integer arg1]
assertEquals[java.lang.Iterable<?> arg0, java.lang.Iterable<?> arg1, java.lang.String arg2]
assertEquals[java.lang.Iterable<?> arg0, java.lang.Iterable<?> arg1]
assertEquals[java.lang.Long arg0, java.lang.Long arg1, java.lang.String arg2]
assertEquals[java.lang.Long arg0, java.lang.Long arg1]
assertEquals[java.lang.Long arg0, long arg1, java.lang.String arg2]
assertEquals[java.lang.Long arg0, long arg1]
assertEquals[java.lang.Object arg0, java.lang.Object arg1, java.lang.String arg2]
assertEquals[java.lang.Object arg0, java.lang.Object arg1]
assertEquals[java.lang.Object[] arg0, java.lang.Object[] arg1, java.lang.String arg2]
assertEquals[java.lang.Object[] arg0, java.lang.Object[] arg1]
assertEquals[java.lang.Short arg0, java.lang.Short arg1, java.lang.String arg2]
assertEquals[java.lang.Short arg0, java.lang.Short arg1]
assertEquals[java.lang.Short arg0, short arg1, java.lang.String arg2]
assertEquals[java.lang.Short arg0, short arg1]
assertEquals[java.lang.String arg0, java.lang.String arg1, java.lang.String arg2]
assertEquals[java.lang.String arg0, java.lang.String arg1]
assertEquals[java.util.Collection<?> arg0, java.util.Collection<?> arg1, java.lang.String arg2]
assertEquals[java.util.Collection<?> arg0, java.util.Collection<?> arg1]
assertEquals[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1, java.lang.String arg2]
assertEquals[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1]
assertEquals[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1, java.lang.String arg2]
assertEquals[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1]
assertEquals[java.util.Set<?> arg0, java.util.Set<?> arg1, java.lang.String arg2]
assertEquals[java.util.Set<?> arg0, java.util.Set<?> arg1]
assertEquals[long arg0, java.lang.Long arg1]
assertEquals[long arg0, long arg1, java.lang.String arg2]
assertEquals[long arg0, long arg1]
assertEquals[long[] arg0, long[] arg1, java.lang.String arg2]
assertEquals[long[] arg0, long[] arg1]
assertEquals[short arg0, java.lang.Short arg1, java.lang.String arg2]
assertEquals[short arg0, java.lang.Short arg1]
assertEquals[short arg0, short arg1, java.lang.String arg2]
assertEquals[short arg0, short arg1]
assertEquals[short[] arg0, short[] arg1, java.lang.String arg2]
assertEquals[short[] arg0, short[] arg1]
assertEqualsDeep[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1, java.lang.String arg2]
assertEqualsDeep[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1]
assertEqualsDeep[java.util.Set<?> arg0, java.util.Set<?> arg1, java.lang.String arg2]
assertEqualsNoOrder[java.lang.Object[] arg0, java.lang.Object[] arg1, java.lang.String arg2]
assertEqualsNoOrder[java.lang.Object[] arg0, java.lang.Object[] arg1]
assertEqualsNoOrder[java.util.Collection<?> arg0, java.util.Collection<?> arg1, java.lang.String arg2]
assertEqualsNoOrder[java.util.Collection<?> arg0, java.util.Collection<?> arg1]
assertEqualsNoOrder[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1, java.lang.String arg2]
assertEqualsNoOrder[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1]
assertFalse[boolean arg0, java.lang.String arg1]
assertFalse[boolean arg0]
assertListContains[java.util.List<T> arg0, java.util.function.Predicate<T> arg1, java.lang.String arg2]
assertListContainsObject[java.util.List<T> arg0, T arg1, java.lang.String arg2]
assertListNotContains[java.util.List<T> arg0, java.util.function.Predicate<T> arg1, java.lang.String arg2]
assertListNotContainsObject[java.util.List<T> arg0, T arg1, java.lang.String arg2]
assertNotEquals[double arg0, double arg1, double arg2, java.lang.String arg3]
assertNotEquals[double arg0, double arg1, double arg2]
assertNotEquals[float arg0, float arg1, float arg2, java.lang.String arg3]
assertNotEquals[float arg0, float arg1, float arg2]
assertNotEquals[java.lang.Object arg0, java.lang.Object arg1, java.lang.String arg2]
assertNotEquals[java.lang.Object arg0, java.lang.Object arg1]
assertNotEquals[java.lang.Object[] arg0, java.lang.Object[] arg1, java.lang.String arg2]
assertNotEquals[java.util.Collection<?> arg0, java.util.Collection<?> arg1, java.lang.String arg2]
assertNotEquals[java.util.Collection<?> arg0, java.util.Collection<?> arg1]
assertNotEquals[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1, java.lang.String arg2]
assertNotEquals[java.util.Iterator<?> arg0, java.util.Iterator<?> arg1]
assertNotEquals[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1, java.lang.String arg2]
assertNotEquals[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1]
assertNotEquals[java.util.Set<?> arg0, java.util.Set<?> arg1, java.lang.String arg2]
assertNotEquals[java.util.Set<?> arg0, java.util.Set<?> arg1]
assertNotEqualsDeep[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1, java.lang.String arg2]
assertNotEqualsDeep[java.util.Map<?, ?> arg0, java.util.Map<?, ?> arg1]
assertNotEqualsDeep[java.util.Set<?> arg0, java.util.Set<?> arg1, java.lang.String arg2]
assertNotEqualsDeep[java.util.Set<?> arg0, java.util.Set<?> arg1]
assertNotNull[java.lang.Object arg0, java.lang.String arg1]
assertNotNull[java.lang.Object arg0]
assertNotSame[java.lang.Object arg0, java.lang.Object arg1, java.lang.String arg2]
assertNotSame[java.lang.Object arg0, java.lang.Object arg1]
assertNull[java.lang.Object arg0, java.lang.String arg1]
assertNull[java.lang.Object arg0]
assertSame[java.lang.Object arg0, java.lang.Object arg1, java.lang.String arg2]
assertSame[java.lang.Object arg0, java.lang.Object arg1]
assertThrows[java.lang.Class<T> arg0, org.testng.Assert$ThrowingRunnable arg1]
assertThrows[java.lang.String arg0, java.lang.Class<T> arg1, org.testng.Assert$ThrowingRunnable arg2]
assertThrows[org.testng.Assert$ThrowingRunnable arg0]
assertTrue[boolean arg0, java.lang.String arg1]
assertTrue[boolean arg0]
expectThrows[java.lang.Class<T> arg0, org.testng.Assert$ThrowingRunnable arg1]
expectThrows[java.lang.String arg0, java.lang.Class<T> arg1, org.testng.Assert$ThrowingRunnable arg2]
fail[]
fail[java.lang.String arg0, java.lang.Throwable arg1]
fail[java.lang.String arg0]

At the end of the day each of them should be migrated in a feasible / functional way.

juherr commented 5 months ago

Did you consider to make the migration to AssertJ instead of JUnit5 ?

Philzen commented 5 months ago

Did you consider to make the migration to AssertJ instead of JUnit5 ?

@juherr That is an excellent point. Generally this is out of scope of this project, as the following projects already cover that:

However your comment made me realize two things.

  1. i will want to run the above recipes on the project i am building this recipe for before running this migration (as i'm also preferring AssertJ assertion handsdown anywhere). As part of that i may get involved in the implementations of those recipes as well, as they may not cover all possible cases yet.
  2. some the recipes in this project (namely the migrations for @Test and SkipException) need an "assertJ" option to be able to cleanly integrate with projects that prefer AssertJ. Created #33 for that, which i consider as a requirement for MVP status of this project.

So thanks! :handshake:

juherr commented 5 months ago

I think we share the same vision.

I was thinking about AssertJ as intermediate step for the testng to junit migration.

  1. Apply the testng to assertj rule (and contribute to be feature complete)
  2. If wanted, apply an assertj to junit5 rule and drop assertj dependency if no more assertj

I've no idea about the complexity of the implementation.

Wdyt?