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

toBeNullIfNullGivenElse

inline fun <reified T : Any> Expect<T?>.toBeNullIfNullGivenElse(noinline assertionCreatorOrNull: (Expect<T>.() -> Unit)?): Expect<T?>

Expects that the subject of the assertion 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 {
    isLessThan(2)
}

fails {
    // sub-assertion fails
    expect<Int?>(1).toBeNullIfNullGivenElse {
        isLessThan(0)
    }
}

Exceptions

AssertionError - Might throw an AssertionError if the assertion made is not correct.

Return
An Expect for the current subject of the assertion.