using junit5/assertJ is there a way for the compil...
# test
r
using junit5/assertJ is there a way for the compiler to figure out that something cannot be null? i.e.
assertNotNull
or
assertThat(nullable).isNotNull
won’t do the trick
l
Why won't
assertNotNull
do the trick?
r
not sure, maybe because it’s in a library?
Copy code
val value: Array<TriggeredOffer>? = response.body()
        assertNotNull(value)
        assertEquals(1, value.size) // doesn't compile
this is what I mean
r
AssertJ would need to implement kotlin contracts for that to work. But obviously they don't (as it is a Java library). You could implement your own assertNotNull though doing the contract stuff and delegating to AssertJ
shameless plug: you could use Atrium instead of AssertJ and write
Copy code
assert(value?.asList()).notToBeNull {
  hasSize(1)
}
r
I will certainly check that out @robstoll 🙂
m
Or write your own function that wraps AssertJ. Either is viable, but from what I’ve seen Atrium is very well done. I haven’t moved from AssertJ (yet), but if I were to move to a Kotlin one, it would be Atrium. Seems the most full-featured Kotlin native assertion library yet.