inline fun <reified T : Any> Expect<T?>.notToEqualNull(): Expect<T>
(source)
Expects that the subject of this
expectation is not null and changes the subject to the non-nullable version.
expect<Int?>(1)
.notToEqualNull() // subject is now of type Int
.toBeLessThan(2)
fails {
expect<Int?>(null)
.notToEqualNull() // fails
.toBeLessThan(2) // not evaluated/reported because `notToEqualNull` already fails
// use `notToEqualNull { ... }` if you want that all expectations are evaluated
}
Return
An Expect with the non-nullable type T (was T?
before).
inline fun <reified T : Any> Expect<T?>.notToEqualNull(noinline assertionCreator: Expect<T>.() -> Unit): Expect<T>
(source)
Expects that the subject of this
expectation is not null and
that it holds all assertions the given assertionCreator creates.
expect<Int?>(1)
.notToEqualNull { // subject is now of type Int
toBeGreaterThan(0)
toBeLessThan(10)
} // subject remains type Int also after the block
.toEqual(1)
fails { // because subject is null, but since we use a block...
expect<Int?>(null).notToEqualNull {
toBeGreaterThan(2) // ...reporting mentions that subject was expected `to be greater than: 2`
}
}
fails { // because sub-expectation fails
expect<Int?>(1).notToEqualNull {
toBeLessThan(0) // fails
toBeGreaterThan(5) // still evaluated even though `toBeLessThan` already fails,
// use `.notToEqualNull().` if you want a fail fast behaviour
}
}
fails {
// because you forgot to define an expectation in the expectation group block
// use `.notToEqualNull()` if this is all you expect
expect<Int?>(1).notToEqualNull { }
}
Return
An Expect with the non-nullable type T (was T?
before)