toEqualNullIfNullGivenElse

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.

Return

an Expect for the subject of this expectation.

Samples

expect<Int?>(null).toEqualNullIfNullGivenElse(null)

fails { // because subject is not null
    expect<Int?>(1).toEqualNullIfNullGivenElse(null)
}

expect<Int?>(1).toEqualNullIfNullGivenElse { // subject inside this expectation-group is of type Int
    toBeLessThan(2)
} // subject here is back to type Int?

fails { // because sub-expectation fails
    expect<Int?>(1).toEqualNullIfNullGivenElse {
        toBeLessThan(0)
    }
}