doc / ch.tutteli.atrium.logic.creating.transformers / SubjectChanger / reported

reported

abstract fun <T, R> reported(container: AssertionContainer<T>, description: Translatable, representation: Any, transformation: (T) -> Option<R>, failureHandler: SubjectChanger.FailureHandler<T, R>, maybeSubAssertions: Option<Expect<R>.() -> Unit>): Expect<R> (source)

Changes to a new subject according to the given transformation -- the change as such is reflected in reporting by the given description and representation.

Explained a bit more in depth: it creates a new Expect incorporating the given transformation whereas the new Expect delegates assertion checking to the given container. The transformation as such can either return the new subject wrapped in a Some or return None in case the transformation cannot be carried out.

This method is useful if you want to change the subject whereas the change as such is assertion like as well, so that it should be reported as well. For instance, say you want to change the subject of type Int? to Int. Since the subject could also be null it makes sense to report this assertion instead of failing with an exception.

Parameters

container - the assertion container with the current subject (before the change)

description - Describes the kind of subject change (e.g. in case of a type change is a).

representation - Representation of the change (e.g. in case of a type transformation the KClass).

transformation - Provides the subject wrapped into a Some if the extraction as such can be carried out otherwise None.

failureHandler - The FailureHandler which shall be used in case the subject cannot be transformed. A failure has the chance to augment the failing assertion representing the failed transformation with further information.

maybeSubAssertions - Optionally, subsequent assertions for the new subject. This is especially useful if the change fails since we can then already show to you (in error reporting) what you wanted to assert about the new subject (which gives you more context to the error).

Return
The newly created Expect for the extracted feature.