doc / ch.tutteli.atrium.creating / DownCastBuilder / cast

cast

fun cast(): IAssertionPlant<TSub> (source)

Performs the down-cast if possible; reports a failure otherwise.

Down-Casting is possible if commonFields's subject is not null and its type is subType (or a sub-type of subType).

In case the down-cast can be performed, it will create an IAssertionPlant and use the down-casted subject of commonFields as IAssertionPlant.subject of the newly created IAssertionPlant. Furthermore, it will add an IAssertion -- representing the performed down-cast (possibly using the description) -- to the newly created IAssertionPlant.

Exceptions

AssertionError - Might throw an AssertionError in case the down-cast cannot be performed or an additionally specified assertion (using withLazyAssertions) does not hold.

IllegalStateException - In case reporting a failure does not throw itself.

Return
The newly created IAssertionPlant for the down-casted subject of commonFields.