doc / ch.tutteli.atrium.api.infix.en_GB / toBeNullIfNullGivenElse

toBeNullIfNullGivenElse

infix fun <T : Any> Expect<T?>.toBeNullIfNullGivenElse(assertionCreatorOrNull: (Expect<T>.() -> Unit)?): Expect<T?> (source)
Deprecated: Use toEqualNullIfNullGivenElse; will be removed with 1.0.0 at the latest

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) toBeNullIfNullGivenElse null

expect<Int?>(1) toBeNullIfNullGivenElse { // subject inside this block is of type Int (actually 1)
    it isLessThan 2
} // subject here is back to type Int?

fails {
    expect<Int?>(1) toBeNullIfNullGivenElse { // subject inside this block is of type Int (actually 1)
        it isLessThan 0
    } // subject here is back to type Int?
}

Return
an Expect for the subject of this expectation.