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 reported because `notToEqualNull` already fails
}
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 you forgot to define an expectation in the expectation group block
// use `notToEqualNull()` if this is all you expect
expect<Int?>(1).notToEqualNull { }
}
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)
}
}
Return
An Expect with the non-nullable type T (was T?
before)