https://kotlinlang.org logo
Title
s

Shervin

05/17/2023, 8:44 AM
Hey everyone! is there any assertion which can understand a mapped object is based on another class? Let's say I have:
val p = Person (name='Sam', age= 30)
and there is function that I want to test and returns 'mapped' version of Person, sth like:
val mp = MappedPerson(name, age, someotherParam)
mp shouldBeDerivedFrom* m
(*shouldBeDerivedFrom doesn't exist I'm just writing my thoughts)
I think this can be helpful in layered architecture tests. Any idea?
a

Adam S

05/17/2023, 9:44 AM
there’s
shouldBeEqualToComparingFields
which uses reflection and thus requires JVM but you could always create your own utility function, which is usually what I prefer - it’s a bit more work but it tends to be more understandable and works better in practice
infix fun Person.shouldBeMappedTo(mp: MappedPerson) { TODO() }
s

Shervin

05/18/2023, 10:44 AM
Thanks Adam I like the idea of creating my own functions for domain objects