Does anyone know of a clean way of doing assertio...
# kotest
m
Does anyone know of a clean way of doing assertions on the
Either
type (Arrow)? The
shouldBeRight()
matcher helps quite a bit but I found myself needing to use
map
to check values within that object
Copy code
val submittedPayment: Either<PaymentEventRepoError, Payment> = eventStore.getLatestPaymentForAccount(123)
          submittedPayment.map { it.amount }.shouldBeRight(50.00.toBigDecimal())
          submittedPayment.map { it.state }.shouldBeRight(PaymentState.PENDING)
Its not so bad but I’m wondering if anyone has a better pattern
s
I think there's shouldBeRight { value -> .... }
which seems like it would be better
m
Ah thanks!
Copy code
responseList.shouldBeRight { it.size.shouldBe(1) }
Definitely feels more intuitive and reads a bit better
s
once kotlin 1.4 is out we can use contracts
Copy code
val right = either.shouldBeRight()
right.name shouldBe "sam"