Instancia de class Kotlin assertEqual

Soy nuevo en java / kotlin. Me gustaría afirmar la igualdad en la siguiente class:

class PlaceCommand(vararg args: String) : ICommand { var direction: Direction = Direction.valueOf(args[1].toUpperCase()) var x: Int = args[2].toInt() var y: Int = args[3].toInt() // ... } 

Qué cambio es necesario para activar:

 class FactoryTest { @Test fun testFactorySuccess() { val args = arrayOf("place", "WEST", "1", "1") val a = PlaceCommand(*args) val b = Factory(args) as PlaceCommand Assert.assertTrue(axequals(bx)) Assert.assertTrue(ayequals(by)) Assert.assertTrue(a.direction.equals(b.direction)) } // ... } 

En algo así como:

 class FactoryTest { @Test fun testFactorySuccess() { val args = arrayOf("place", "WEST", "1", "1") Assert.assertEqual(PlaceCommand(*args), Factory(args) as PlaceCommand) # or Assert.assertTrue(PlaceCommand(*args).equal(Factory(args) as PlaceCommand)) } // ... } 

Gracias.

Puede anular el método equals en PlaceCommand

 override fun equals(other: Any?): Boolean{ if (this === other) return true if (other?.javaClass != javaClass) return false other as PlaceCommand if (x != other.x) return false if (y != other.y) return false return true } 

Si usa Intellij Idea puede presionar Alt+Insert para generarlo.

Entonces simplemente use == operador para probar la igualdad

Assert.assertTrue(PlaceCommand(*args) == (Factory(args) as PlaceCommand))

En kotlin == es equivalente a a?.equals(b) ?: b === null . === es igualdad de reference