fun <T : Any> Expect<T?>.toEqualNullIfNullGivenElse(assertionCreatorOrNull: (Expect<T>.() -> Unit)?): Expect<T?>
(source)
Expects that the subject of this
expectation is either null
in case assertionCreatorOrNull
is null
or is not null
and holds all assertions assertionCreatorOrNull creates.
expect<Int?>(null).toEqualNullIfNullGivenElse(null)
fails { // because subject is not null
expect<Int?>(1).toEqualNullIfNullGivenElse(null)
}
expect<Int?>(1).toEqualNullIfNullGivenElse { // subject inside this block is of type Int
toBeLessThan(2)
} // subject here is back to type Int?
fails { // because sub-expectation fails
expect<Int?>(1).toEqualNullIfNullGivenElse {
toBeLessThan(0)
}
}
Return
an Expect for the subject of this
expectation.