kotools / libraries

Multiplatform libraries for expressive programming with Kotlin.
https://kotools.github.io/libraries
MIT License
0 stars 0 forks source link

`Throwable`'s message assertion #73

Open LVMVRQUXL opened 1 year ago

LVMVRQUXL commented 1 year ago

Description

The problem

For checking if an exception has a message, users have to do the following boilerplate code in each test:

import kotools.assert.assertNotNull
import kotools.assert.assertTrue

fun test() {
   assertFailsWith<Throwable> { /* ... */ }
        .message
        .assertNotNull()
        .isNotBlank()
        .assertTrue()
}

The solution

Introduce a new Throwable.assertHasNotBlankMessage function checking that this throwable has a not blank message.

import kotools.assert.assertFailsWith

/** Asserts that this exception has a not blank message. */
fun <A : Throwable> A.assertHasNotBlankMessage(): Unit = TODO()

fun test() {
   assertFailsWith<Throwable> { /* ... */ }
        .assertHasNotBlankMessage()
}

Checklist