Issue
How would you write assertThat(foo, instanceOf(Bar.class)) with Kotlin?
Seems that it does not like the .class
I would like to go for an assertion which is a bit more "precise" than just an assertTrue(foo is Bar) if possible
Solution
Bar::class returns instance of KClass, which is Kotlin equivalent of Java's Class.
instanceOf method requires Class instance, not KClass, so you have to convert it using Bar::class.java.
So your assertion should be like:
assertThat(foo, instanceOf(Bar::class.java))
More info about Java interop you can find here.
Also you can have a look at Hamkrest library which may add more fluency to your assertions:
assert.that(foo, isA<Bar>())
Answered By - ledniov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.