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

notToBeNull

inline infix fun <reified T : Any> Expect<T?>.notToBeNull(o: o): Expect<T> (source)
Deprecated: Use notToEqualNull; will be removed with 1.0.0 at the latest

Expects that the subject of this expectation is not null and changes the subject to the non-nullable version.

expect<Int?>(1) notToBeNull o isLessThan 2
//                   | subject is now of type Int (actually 1)

fails {
    expect<Int?>(null) notToBeNull o isLessThan 2
    //                      |             | not reported because `notToBeNull` already fails
    //                      | fails
}

Parameters

o - The filler object o.

Return
An Expect with the non-nullable type T (was T? before).

Since
0.12.0

inline infix fun <reified T : Any> Expect<T?>.notToBeNull(noinline assertionCreator: Expect<T>.() -> Unit): Expect<T> (source)
Deprecated: Use notToEqualNull; will be removed with 1.0.0 at the latest

Expects that the subject of this expectation is not null and that it holds all assertions the given assertionCreator creates.

expect<Int?>(1) notToBeNull { // subject is now of type Int
    it isGreaterThan 0
    it isLessThan 10
} toEqual 1 // subject here remains type Int

fails {
    // because you forgot to define an assertion in the assertion group block
    // use `notToBeNull()` if this is all you want to assert
    expect<Int?>(1) notToBeNull { }
}

fails {
    // notToBeNull already fails, reporting mentions that subject was expected `to be: 2`
    expect<Int?>(null) notToBeNull { // subject inside this block is of type Int (actually 1)
        it toEqual 2
    }  // subject here remains type Int
}

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

Return
An Expect with the non-nullable type T (was T? before)