All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.kotlin.ch.tutteli.atrium.api.verbs.assert.kt Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package ch.tutteli.atrium.api.verbs

import ch.tutteli.atrium.api.verbs.AssertionVerb.ASSERT
import ch.tutteli.atrium.assertions.Assertion
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.creating.FeatureExpect
import ch.tutteli.atrium.creating.RootExpect
import ch.tutteli.atrium.logic._logic
import ch.tutteli.atrium.logic.creating.RootExpectBuilder
import ch.tutteli.atrium.logic.manualFeature

/**
 * Creates an [Expect] for the given [subject].
 *
 * @param subject The subject for which we are going to postulate assertions.
 *
 * @return The newly created assertion container.
 * @throws AssertionError in case an assertion does not hold.
 */
fun  assert(subject: T): RootExpect =
    RootExpectBuilder.forSubject(subject)
        .withVerb(ASSERT)
        .withoutOptions()
        .build()

/**
 * Creates an [Expect] for the given [subject] and [Expect.addAssertionsCreatedBy] the
 * given [assertionCreator]-lambda where the created [Assertion]s are added as a group and reported as a whole.
 *
 * @param subject The subject for which we are going to postulate assertions.
 * @param assertionCreator Assertion group block with a non-fail fast behaviour.
 * @return The newly created assertion container.
 * @throws AssertionError in case an assertion does not hold.
 */
fun  assert(subject: T, assertionCreator: Expect.() -> Unit): Expect =
    assert(subject).addAssertionsCreatedBy(assertionCreator)

@Deprecated(
    "`assert` should not be nested, use `feature` instead.",
    ReplaceWith(
        "feature(\"name of the feature\") { newSubject /* see also other overloads which do not require `name of the feature` and provide the subject as parameter, e.g. feature { f(it::yourFeature) } */}",
        "ch.tutteli.atrium.api.infix.en_GB.feature",
        "ch.tutteli.atrium.api.fluent.en_GB.feature"
    )
)
fun  Expect.assert(newSubject: R): FeatureExpect =
    _logic.manualFeature(ASSERT) { newSubject }.transform()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy