doc / ch.tutteli.atrium.domain.builders.utils

Package ch.tutteli.atrium.domain.builders.utils

Contains utility functions for APIs.

Types

Group

interface Group<out T>

GroupWithNullableEntries

interface GroupWithNullableEntries<out T> : Group<T>

Represents a group of T (where T: Any?) which can be converted to a List<T>

GroupWithoutNullableEntries

interface GroupWithoutNullableEntries<out T : Any> : Group<T>

Represents a group of T (where T: Any) which can be converted to a List<T>

Functions

groupsToList

fun <T> groupsToList(firstGroup: Group<T>, secondGroup: Group<T>, otherGroups: Array<out Group<T>>): List<List<T>>

Adds the given firstGroup, the secondGroup and the otherGroups into a new List and returns it.

nullable

fun <T> nullable(t: T): T?

Turns the given type into a nullable type.

fun <T> nullable(t: KFunction0<T>): KFunction0<T?>
fun <T1, R> nullable(t: KFunction1<T1, R>): KFunction1<T1, R?>
fun <T1, T2, R> nullable(t: KFunction2<T1, T2, R>): KFunction2<T1, T2, R?>
fun <T1, T2, T3, R> nullable(t: KFunction3<T1, T2, T3, R>): KFunction3<T1, T2, T3, R?>
fun <T1, T2, T3, T4, R> nullable(t: KFunction4<T1, T2, T3, T4, R>): KFunction4<T1, T2, T3, T4, R?>
fun <T1, T2, T3, T4, T5, R> nullable(t: KFunction5<T1, T2, T3, T4, T5, R>): KFunction5<T1, T2, T3, T4, T5, R?>

Turns the given function reference into a function reference with a nullable return type.

nullableContainer

fun <T> nullableContainer(iterable: Iterable<T>): Iterable<T?>

Turns an Iterable into an iterable with a nullable entry type.

fun <T> nullableContainer(arr: Array<out T>): Array<out T?>

Turns an Array into an array with a nullable entry type.

nullableKeyMap

fun <K, V : Any> nullableKeyMap(map: Map<out K, V>): Map<out K?, V>

Turns a Map into a map with a nullable key type.

nullableValueMap

fun <K : Any, V> nullableValueMap(map: Map<K, V>): Map<K, V?>

Turns a Map into a map with a nullable value type.

subAssert

fun <T : Any> subAssert(assertionCreator: AssertionPlant<T>.() -> Unit): AssertionPlant<T>.() -> Unit

Helper function to circumvent Kotlin inference issues involving lambdas such as:

validateAtMost

fun validateAtMost(times: Int, atMostCall: (Int) -> String, atLeastCall: (Int) -> String, exactlyCall: (Int) -> String): Unit

Validates that times is not 1; throws an IllegalArgumentException otherwise, pointing the user to use the given exactlyCall instead of the given atMostCall.

validateButAtMost

fun validateButAtMost(atLeastTimes: Int, butAtMostTimes: Int, atLeastButAtMostCall: (Int, Int) -> String, atLeastCall: (Int) -> String, butAtMostCall: (Int) -> String, exactlyCall: (Int) -> String): Unit

Validates that atLeastTimes is not equal to or greater than butAtMostTimes; throws IllegalArgumentException otherwise, pointing the user to use the given exactlyCall in case atLeastTimes equals butAtMostTimes.