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

notToEqualNull

inline infix fun <reified T : Any> Expect<T?>.notToEqualNull(o: o): Expect<T> (source)

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

expect<Int?>(1) notToEqualNull o toBeLessThan 2
//                             | subject is now of type Int

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

Parameters

o - The filler object o.

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

Since
0.17.0

inline infix fun <reified T : Any> Expect<T?>.notToEqualNull(noinline assertionCreator: Expect<T>.() -> Unit): Expect<T> (source)

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

expect<Int?>(1) notToEqualNull { // subject is now of type Int
    it toBeGreaterThan 0
    it toBeLessThan 10
} /* subject remains type Int also after the block
*/ toEqual 1


fails { // because subject is null, but since we use a block...
    expect<Int?>(null) notToEqualNull {
        it toBeGreaterThan 2  // ...reporting mentions that subject was expected `to be greater than: 2`
    }
}

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

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

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

Since
0.17.0