Kotlin class instance assert not correct -
i'm converting java project kotlin.  i've converted user object kotlin , when run existing junit tests in java i'm getting error between 2 instances of kotlin user object.
user.kt:
data class user ( @id @generatedvalue(strategy = generationtype.sequence, generator = "sequencegenerator") @sequencegenerator(name = "sequencegenerator") var id: long? = null, ... )   testutil.java
import static org.assertj.core.api.assertions.assertthat;  public class testutil {     public static void equalsverifier(class clazz) throws exception {         object domainobject1 = clazz.getconstructor().newinstance();         // test instance of same class         object domainobject2 = clazz.getconstructor().newinstance();         assertthat(domainobject1).isnotequalto(domainobject2);     } }   the assertthat(domainobject1).isnotequalto(domainobject2) test fails, believe in java comparison not done correctly on kotlin class.  if run through debugger, can see domainobject1 , domainobject2 different instances.
is possible test case pass? same test case used other java classes, has work both java , kotlin classes.
the isnotequalto calls equals. kotlin class implements correct equals method data class. domainobject1.equals(domainobject2) true. behavior correct.
just @ assertj document:
isnotsameas(object other):     verifies actual value not same given one,     ie using == comparison.   i think should try:
    assertthat(domainobject1).isnotsameas(domainobject2);      
Comments
Post a Comment