strikt-core / strikt.api / Assertion / Builder

Builder

interface Builder<T>

Used to construct assertions.

Parameters

T - the subject type.

See Also

expectThat

Assertion

Functions

and

Evaluates a block of assertions on the current subject.

abstract infix fun and(assertions: Builder<T>.() -> Unit): Builder<T>

assert

Evaluates a condition that may pass or fail.

open fun assert(description: String, assert: AtomicAssertion.(T) -> Unit): Builder<T>
abstract fun assert(description: String, expected: Any?, assert: AtomicAssertion.(T) -> Unit): Builder<T>

assertThat

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

open fun assertThat(description: String, assert: (T) -> Boolean): Builder<T>
open fun assertThat(description: String, expected: Any?, assert: (T) -> Boolean): Builder<T>

chain

Deprecated form of with((T) -> R).

open fun <R> chain(function: (T) -> R): DescribeableBuilder<R>

Deprecated form of with(String, (T) -> R).

open fun <R> chain(description: String, function: (T) -> R): DescribeableBuilder<R>

compose

Allows an assertion to be composed of multiple sub-assertions such as on fields of an object or elements of a collection.

abstract fun compose(description: String, expected: Any?, assertions: Builder<T>.(T) -> Unit): CompoundAssertions<T>
open fun compose(description: String, assertions: Builder<T>.(T) -> Unit): CompoundAssertions<T>

get

Maps the assertion subject to the result of function. This is useful for chaining to property values or method call results on the subject.

open fun <R> get(function: T.() -> R): DescribeableBuilder<R>
abstract fun <R> get(description: String, function: T.() -> R): DescribeableBuilder<R>

not

Reverses any assertions chained after this method.

abstract fun not(): Builder<T>

Evaluates a block of assertions on the current subject by executing them in reverse.

abstract infix fun not(assertions: Builder<T>.() -> Unit): Builder<T>

passesIf

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

open fun passesIf(description: String, assert: (T) -> Boolean): Builder<T>
open fun passesIf(description: String, expected: Any?, assert: (T) -> Boolean): Builder<T>

with

Runs a group of assertions on the subject returned by function.

abstract fun <R> with(description: String, function: T.() -> R, block: Builder<R>.() -> Unit): Builder<T>
open fun <R> with(function: T.() -> R, block: Builder<R>.() -> Unit): Builder<T>