notToEqualNull
Expects that the subject of this
expectation is not null and changes the subject to the non-nullable version.
Return
Samples
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
}
inline fun <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.
Return
Samples
expect<Int?>(1)
.notToEqualNull { // subject is now of type Int
toBeGreaterThan(0)
toBeLessThan(10)
} // subject remains type Int also after the expectation-group
.toEqual(1)
fails { // because subject is null, but since we use an expectation-group...
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 { }
}