open up non-nullable overloads for Map assertions

...and delete the once which have been used for nullable
This commit is contained in:
Robert Stoll
2019-03-18 21:21:37 +01:00
parent 4242811c40
commit 6c654ef398
13 changed files with 255 additions and 227 deletions

View File

@@ -7,12 +7,11 @@ import ch.tutteli.atrium.creating.AssertionPlantNullable
import ch.tutteli.atrium.domain.builders.AssertImpl
import ch.tutteli.kbox.glue
import kotlin.js.JsName
import kotlin.jvm.JvmName
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [entry]'s [Pair.first]
* with a corresponding value as defined by [entry]'s [Pair.second] -- optionally the same assertions are created
* for the [otherEntries].
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by
* [entry]'s [Pair.first] with a corresponding value as defined by [entry]'s [Pair.second]
* -- optionally the same assertions are created for the [otherEntries].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and [entry] is
* defined as `'a' to 1` and one of the [otherEntries] is defined as `'a' to 1` as well, then both match,
@@ -21,41 +20,9 @@ import kotlin.jvm.JvmName
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JsName("enthaelt")
fun <K, V : Any, T: Map<out K, V>> Assert<T>.enthaelt(entry: Pair<K, V>, vararg otherEntries: Pair<K, V>)
fun <K, V, T: Map<out K, V>> Assert<T>.enthaelt(entry: Pair<K, V>, vararg otherEntries: Pair<K, V>)
= addAssertion(AssertImpl.map.contains(this, entry glue otherEntries))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [entry]'s [Pair.first]
* with a corresponding value as defined by [entry]'s [Pair.second] -- optionally the same assertions are created
* for the [otherEntries].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and [entry] is
* defined as `'a' to 1` and one of the [otherEntries] is defined as `'a' to 1` as well, then both match,
* even though they match the same entry.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("enthaeltNullable")
inline fun <K, reified V: Any, T: Map<out K, V?>> Assert<T>.enthaelt(entry: Pair<K, V?>, vararg otherEntries: Pair<K, V?>)
= addAssertion(AssertImpl.map.containsNullable(this, V::class, entry glue otherEntries))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which holds all assertions [keyValue]'s [valueAssertionCreator][KeyValue.valueAssertionCreatorOrNull] might create.
* -- optionally the same assertions are created for the [otherKeyValues].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and [keyValue] is
* defined as `Key('a') { isGreaterThan(0) }` and one of the [otherKeyValues] is defined as `Key('a') { isLessThan(2) }`
* then both match, even though they match the same entry.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
fun <K, V : Any, T: Map<out K, V>> Assert<T>.enthaelt(keyValue: KeyValue<K, V, Assert<V>.() -> Unit>, vararg otherKeyValues: KeyValue<K, V, Assert<V>.() -> Unit>)
= addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, (keyValue glue otherKeyValues).map { it.toPair() }))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which either holds all assertions [keyValue]'s
@@ -70,9 +37,10 @@ fun <K, V : Any, T: Map<out K, V>> Assert<T>.enthaelt(keyValue: KeyValue<K, V, A
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("enthaeltNullable")
inline fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.enthaelt(keyValue: KeyValue<K, V, (Assert<V>.() -> Unit)?>, vararg otherKeyValues: KeyValue<K, V, (Assert<V>.() -> Unit)?>)
= addAssertion(AssertImpl.map.containsKeyWithNullableValueAssertions(this, V::class, (keyValue glue otherKeyValues).map { it.toPair() }))
fun <K, V : Any, T: Map<out K, V?>> Assert<T>.enthaelt(
keyValue: KeyValue<K, V>,
vararg otherKeyValues: KeyValue<K, V>
) = addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, (keyValue glue otherKeyValues).map { it.toPair() }))
/**
@@ -94,7 +62,6 @@ fun <K> Assert<Map<out K, *>>.enthaeltNichtKey(key: K)
= addAssertion(AssertImpl.map.containsNotKey(this, key))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains the given [key], creates a feature
* assertion plant for corresponding value and returns the newly created plant.

View File

@@ -57,8 +57,8 @@ class Eintraege<in T : Any>(
* Parameter object to express a key/value [Pair] whose value type is a lambda with an
* [Assert][AssertionPlant] receiver, which means one can either pass a lambda or `null`.
*/
data class KeyValue<out K, V : Any, A: ((Assert<V>) -> Unit)?>(val key: K, val valueAssertionCreatorOrNull: A) {
fun toPair(): Pair<K, A> = key to valueAssertionCreatorOrNull
data class KeyValue<out K, V : Any>(val key: K, val valueAssertionCreatorOrNull: (Assert<V>.() -> Unit)?) {
fun toPair(): Pair<K, (Assert<V>.() -> Unit)?> = key to valueAssertionCreatorOrNull
override fun toString(): String
= "KeyValue(key=$key, value=${if (valueAssertionCreatorOrNull == null) "null" else "lambda"})"
}

View File

@@ -3,6 +3,7 @@ package ch.tutteli.atrium.api.cc.de_CH
import ch.tutteli.atrium.AssertionVerbFactory
import ch.tutteli.atrium.creating.Assert
import ch.tutteli.atrium.domain.builders.utils.mapArguments
import ch.tutteli.atrium.esGilt
import kotlin.reflect.KFunction3
class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
@@ -22,8 +23,8 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
companion object {
private val containsFun : KFunction3<Assert<Map<out String, Int>>, Pair<String, Int>, Array<out Pair<String, Int>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::enthaelt
private val containsNullableFun : KFunction3<Assert<Map<out String?, Int?>>, Pair<String?, Int?>, Array<out Pair<String?, Int?>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::enthaelt
private val containsKeyWithValueAssertionsFun : KFunction3<Assert<Map<out String, Int>>, KeyValue<String, Int, (Assert<Int>) -> Unit>, Array<out KeyValue<String, Int, (Assert<Int>) -> Unit>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::enthaelt
private val containsKeyWithNullableValueAssertionsFun : KFunction3<Assert<Map<out String?, Int?>>, KeyValue<String?, Int, ((Assert<Int>) -> Unit)?>, Array<out KeyValue<String?, Int, ((Assert<Int>) -> Unit)?>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::enthaelt
private val containsKeyWithValueAssertionsFun : KFunction3<Assert<Map<out String, Int>>, KeyValue<String, Int>, Array<out KeyValue<String, Int>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::enthaelt
private val containsKeyWithNullableValueAssertionsFun : KFunction3<Assert<Map<out String?, Int?>>, KeyValue<String?, Int>, Array<out KeyValue<String?, Int>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::enthaelt
fun contains(plant: Assert<Map<out String, Int>>, keyValue: Pair<String, Assert<Int>.() -> Unit>, otherKeyValues: Array<out Pair<String, Assert<Int>.() -> Unit>>)
= mapArguments(keyValue, otherKeyValues).to { KeyValue(it.first, it.second) }.let { (first, others) ->
@@ -35,5 +36,65 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
plant.enthaelt(first, *others)
}
}
@Suppress("unused")
private fun ambiguityTest() {
val map = mapOf(1 to "a")
val nullableKeyMap = mapOf(1 as Int? to "a")
val nullableValueMap = mapOf(1 to "a" as String?)
val nullableKeyValueMap = mapOf(1 as Int? to "a" as String?)
esGilt(map).enthaelt(1 to "a")
esGilt(map).enthaelt(1 to "a", 2 to "b")
esGilt(map).enthaelt(KeyValue(1){})
esGilt(map).enthaelt(KeyValue(1){}, KeyValue(2){})
esGilt(nullableKeyMap).enthaelt(1 to "a")
esGilt(nullableKeyMap).enthaelt(1 to "a", 2 to "b")
esGilt(nullableKeyMap).enthaelt(KeyValue(1){})
esGilt(nullableKeyMap).enthaelt(KeyValue(1){}, KeyValue(2){})
esGilt(nullableKeyMap).enthaelt(null to "a")
esGilt(nullableKeyMap).enthaelt(null to "a", null to "b")
esGilt(nullableKeyMap).enthaelt(null to "a", 2 to "b")
esGilt(nullableKeyMap).enthaelt(KeyValue(null){})
esGilt(nullableKeyMap).enthaelt(KeyValue(null){}, KeyValue(null){})
esGilt(nullableKeyMap).enthaelt(KeyValue(null){}, KeyValue(2){})
esGilt(nullableValueMap).enthaelt(1 to "a")
esGilt(nullableValueMap).enthaelt(1 to "a", 2 to "b")
esGilt(nullableValueMap).enthaelt(KeyValue(1){})
esGilt(nullableValueMap).enthaelt(KeyValue(1){}, KeyValue(2){})
esGilt(nullableValueMap).enthaelt(1 to null)
esGilt(nullableValueMap).enthaelt(1 to null, 2 to null)
esGilt(nullableValueMap).enthaelt(1 to null, 2 to "a")
esGilt(nullableValueMap).enthaelt(KeyValue(1, null))
esGilt(nullableValueMap).enthaelt(KeyValue(1, null), KeyValue(2, null))
esGilt(nullableValueMap).enthaelt(KeyValue(1, null), KeyValue(2){})
esGilt(nullableKeyValueMap).enthaelt(1 to "a")
esGilt(nullableKeyValueMap).enthaelt(1 to "a", 2 to "b")
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1){})
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1){}, KeyValue(2){})
esGilt(nullableKeyValueMap).enthaelt(null to "a")
esGilt(nullableKeyValueMap).enthaelt(null to "a", null to "b")
esGilt(nullableKeyValueMap).enthaelt(null to "a", 2 to "b")
esGilt(nullableKeyValueMap).enthaelt(KeyValue(null){})
esGilt(nullableKeyValueMap).enthaelt(KeyValue(null){}, KeyValue(null){})
esGilt(nullableKeyValueMap).enthaelt(KeyValue(null){}, KeyValue(2){})
esGilt(nullableKeyValueMap).enthaelt(1 to null)
esGilt(nullableKeyValueMap).enthaelt(1 to null, 2 to null)
esGilt(nullableKeyValueMap).enthaelt(1 to null, 2 to "a")
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1, null))
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1, null), KeyValue(2, null))
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1, null), KeyValue(2){})
esGilt(nullableKeyValueMap).enthaelt(null to null)
esGilt(nullableKeyValueMap).enthaelt(null to null, null to null)
esGilt(nullableKeyValueMap).enthaelt(1 to null, null to "a")
esGilt(nullableKeyValueMap).enthaelt(KeyValue(null, null))
esGilt(nullableKeyValueMap).enthaelt(KeyValue(null, null), KeyValue(null, null))
esGilt(nullableKeyValueMap).enthaelt(KeyValue(1, null), KeyValue(null){})
}
}

View File

@@ -7,7 +7,6 @@ import ch.tutteli.atrium.creating.AssertionPlantNullable
import ch.tutteli.atrium.domain.builders.AssertImpl
import ch.tutteli.kbox.glue
import kotlin.js.JsName
import kotlin.jvm.JvmName
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValuePair]'s [Pair.first]
@@ -21,43 +20,9 @@ import kotlin.jvm.JvmName
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JsName("contains")
fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>)
fun <K, V, T: Map<out K, V>> Assert<T>.contains(keyValuePair: Pair<K, V>, vararg otherPairs: Pair<K, V>)
= addAssertion(AssertImpl.map.contains(this, keyValuePair glue otherPairs))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyNullableValuePair]'s [Pair.first]
* with a corresponding value as defined by [keyNullableValuePair]'s [Pair.second] -- optionally the same assertions
* are created for the [otherEntries].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and [keyNullableValuePair] is
* defined as `'a' to 1` and one of the [otherEntries] is defined as `'a' to 1` as well, then both match,
* even though they match the same entry.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline fun <K, reified V: Any, T: Map<out K, V?>> Assert<T>.contains(keyNullableValuePair: Pair<K, V?>, vararg otherEntries: Pair<K, V?>)
= addAssertion(AssertImpl.map.containsNullable(this, V::class, keyNullableValuePair glue otherEntries))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which holds all assertions [keyValue]'s [KeyValue.valueAssertionCreatorOrNull] might create.
* -- optionally the same assertions are created for the [otherKeyValues].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and [keyValue] is
* defined as `Key('a') { isGreaterThan(0) }` and one of the [otherKeyValues] is defined as `Key('a') { isLessThan(2) }`
* , then both match, even though they match the same entry.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(
keyValue: KeyValue<K, V, Assert<V>.() -> Unit>,
vararg otherKeyValues: KeyValue<K, V, Assert<V>.() -> Unit>
) = addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, (keyValue glue otherKeyValues).map { it.toPair() }))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which either holds all assertions [keyValue]'s
@@ -72,11 +37,10 @@ fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(
keyValue: KeyValue<K, V, (Assert<V>.() -> Unit)?>,
vararg otherKeyValues: KeyValue<K, V, (Assert<V>.() -> Unit)?>
) = addAssertion(AssertImpl.map.containsKeyWithNullableValueAssertions(this, V::class, (keyValue glue otherKeyValues).map { it.toPair() }))
fun <K, V : Any, T: Map<out K, V?>> Assert<T>.contains(
keyValue: KeyValue<K, V>,
vararg otherKeyValues: KeyValue<K, V>
) = addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, (keyValue glue otherKeyValues).map { it.toPair() }))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains the given [key].

View File

@@ -14,7 +14,7 @@ import ch.tutteli.kbox.glue
/**
* Parameter object to express a [Group] with a single identification lambda.
*
In case `null` is used for the identification lambda then it is expected that the corresponding entry
In case `null` is used for the identification lambda then it is expected that the corresponding entry
* is `null` as well.
*
* @param assertionCreatorOrNull The identification lambda identifying the entry where an entry is considered
@@ -53,8 +53,8 @@ class Entries<in T : Any>(
* Parameter object to express a key/value [Pair] whose value type is a nullable lambda with an
* [Assert][AssertionPlant] receiver, which means one can either pass a lambda or `null`.
*/
data class KeyValue<out K, V : Any, A: ((Assert<V>) -> Unit)?>(val key: K, val valueAssertionCreatorOrNull: A) {
fun toPair(): Pair<K, A> = key to valueAssertionCreatorOrNull
data class KeyValue<out K, V : Any>(val key: K, val valueAssertionCreatorOrNull: (Assert<V>.() -> Unit)?) {
fun toPair(): Pair<K, (Assert<V>.() -> Unit)?> = key to valueAssertionCreatorOrNull
override fun toString(): String
= "KeyValue(key=$key, value=${if (valueAssertionCreatorOrNull == null) "null" else "lambda"})"
}

View File

@@ -3,6 +3,7 @@ package ch.tutteli.atrium.api.cc.en_GB
import ch.tutteli.atrium.creating.Assert
import ch.tutteli.atrium.domain.builders.utils.mapArguments
import ch.tutteli.atrium.verbs.internal.AssertionVerbFactory
import ch.tutteli.atrium.verbs.internal.assert
import kotlin.reflect.KFunction3
class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
@@ -10,7 +11,7 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
containsFun.name to Assert<Map<out String, Int>>::contains,
containsNullableFun.name to Assert<Map<out String?, Int?>>::contains,
"${containsKeyWithValueAssertionsFun.name} ${KeyValue::class.simpleName}" to Companion::contains,
"${containsKeyWithNullableValueAssertionsFun.name} ${KeyNullableValue::class.simpleName}" to Companion::containsNullable,
"${containsKeyWithNullableValueAssertionsFun.name} ${KeyValue::class.simpleName}" to Companion::containsNullable,
Assert<Map<out String, *>>::containsKey.name to Assert<Map<out String, *>>::containsKey,
Assert<Map<out String?, *>>::containsKey.name to Assert<Map<out String?, *>>::containsKey,
Assert<Map<out String, *>>::containsKey.name to Assert<Map<out String, *>>::containsNotKey,
@@ -22,8 +23,8 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
companion object {
private val containsFun : KFunction3<Assert<Map<out String, Int>>, Pair<String, Int>, Array<out Pair<String, Int>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::contains
private val containsNullableFun : KFunction3<Assert<Map<out String?, Int?>>, Pair<String?, Int?>, Array<out Pair<String?, Int?>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::contains
private val containsKeyWithValueAssertionsFun : KFunction3<Assert<Map<out String, Int>>, KeyValue<String, Int, Assert<Int>.() -> Unit>, Array<out KeyValue<String, Int, Assert<Int>.() -> Unit>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::contains
private val containsKeyWithNullableValueAssertionsFun : KFunction3<Assert<Map<out String?, Int?>>, KeyValue<String?, Int, (Assert<Int>.() -> Unit)?>, Array<out KeyValue<String?, Int, (Assert<Int>.() -> Unit)?>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::contains
private val containsKeyWithValueAssertionsFun : KFunction3<Assert<Map<out String, Int>>, KeyValue<String, Int>, Array<out KeyValue<String, Int>>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::contains
private val containsKeyWithNullableValueAssertionsFun : KFunction3<Assert<Map<out String?, Int?>>, KeyValue<String?, Int>, Array<out KeyValue<String?, Int>>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::contains
fun contains(plant: Assert<Map<out String, Int>>, keyValue: Pair<String, Assert<Int>.() -> Unit>, otherKeyValues: Array<out Pair<String, Assert<Int>.() -> Unit>>)
= mapArguments(keyValue, otherKeyValues).to { KeyValue(it.first, it.second) }.let { (first, others) ->
@@ -35,4 +36,64 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
plant.contains(first, *others)
}
}
@Suppress("unused")
private fun ambiguityTest() {
val map = mapOf(1 to "a")
val nullableKeyMap = mapOf(1 as Int? to "a")
val nullableValueMap = mapOf(1 to "a" as String?)
val nullableKeyValueMap = mapOf(1 as Int? to "a" as String?)
assert(map).contains(1 to "a")
assert(map).contains(1 to "a", 2 to "b")
assert(map).contains(KeyValue(1){})
assert(map).contains(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyMap).contains(1 to "a")
assert(nullableKeyMap).contains(1 to "a", 2 to "b")
assert(nullableKeyMap).contains(KeyValue(1){})
assert(nullableKeyMap).contains(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyMap).contains(null to "a")
assert(nullableKeyMap).contains(null to "a", null to "b")
assert(nullableKeyMap).contains(null to "a", 2 to "b")
assert(nullableKeyMap).contains(KeyValue(null){})
assert(nullableKeyMap).contains(KeyValue(null){}, KeyValue(null){})
assert(nullableKeyMap).contains(KeyValue(null){}, KeyValue(2){})
assert(nullableValueMap).contains(1 to "a")
assert(nullableValueMap).contains(1 to "a", 2 to "b")
assert(nullableValueMap).contains(KeyValue(1){})
assert(nullableValueMap).contains(KeyValue(1){}, KeyValue(2){})
assert(nullableValueMap).contains(1 to null)
assert(nullableValueMap).contains(1 to null, 2 to null)
assert(nullableValueMap).contains(1 to null, 2 to "a")
assert(nullableValueMap).contains(KeyValue(1, null))
assert(nullableValueMap).contains(KeyValue(1, null), KeyValue(2, null))
assert(nullableValueMap).contains(KeyValue(1, null), KeyValue(2){})
assert(nullableKeyValueMap).contains(1 to "a")
assert(nullableKeyValueMap).contains(1 to "a", 2 to "b")
assert(nullableKeyValueMap).contains(KeyValue(1){})
assert(nullableKeyValueMap).contains(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyValueMap).contains(null to "a")
assert(nullableKeyValueMap).contains(null to "a", null to "b")
assert(nullableKeyValueMap).contains(null to "a", 2 to "b")
assert(nullableKeyValueMap).contains(KeyValue(null){})
assert(nullableKeyValueMap).contains(KeyValue(null){}, KeyValue(null){})
assert(nullableKeyValueMap).contains(KeyValue(null){}, KeyValue(2){})
assert(nullableKeyValueMap).contains(1 to null)
assert(nullableKeyValueMap).contains(1 to null, 2 to null)
assert(nullableKeyValueMap).contains(1 to null, 2 to "a")
assert(nullableKeyValueMap).contains(KeyValue(1, null))
assert(nullableKeyValueMap).contains(KeyValue(1, null), KeyValue(2, null))
assert(nullableKeyValueMap).contains(KeyValue(1, null), KeyValue(2){})
assert(nullableKeyValueMap).contains(null to null)
assert(nullableKeyValueMap).contains(null to null, null to null)
assert(nullableKeyValueMap).contains(1 to null, null to "a")
assert(nullableKeyValueMap).contains(KeyValue(null, null))
assert(nullableKeyValueMap).contains(KeyValue(null, null), KeyValue(null, null))
assert(nullableKeyValueMap).contains(KeyValue(1, null), KeyValue(null){})
}
}

View File

@@ -8,85 +8,29 @@ import ch.tutteli.atrium.creating.Assert
import ch.tutteli.atrium.creating.AssertionPlant
import ch.tutteli.atrium.domain.builders.AssertImpl
import kotlin.js.JsName
import kotlin.jvm.JvmName
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValuePair]'s [Pair.first]
* with a corresponding value as defined by [keyValuePair]'s [Pair.second].
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by
* [keyValuePair]'s [Pair.first] with a corresponding value as defined by [keyValuePair]'s [Pair.second].
*
* Delegates to `contains Pairs(entry)`.
* Delegates to `contains Pairs(keyValuePair)`.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JsName("contains")
infix fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValuePair: Pair<K, V>)
infix fun <K, V, T: Map<out K, V>> Assert<T>.contains(keyValuePair: Pair<K, V>)
= this contains Pairs(keyValuePair)
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains for each entry in [keyValuePairs], a key as defined by
* entry's [Pair.first] with a corresponding value as defined by entry's [Pair.second].
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and one pair in [keyValuePairs]
* is defined as `'a' to 1` and another pair in [Pairs] is defined as `'a' to 1` as well, then both match,
* even though they match the same entry.
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains for each entry in [keyValuePairs],
* a key as defined by entry's [Pair.first] with a corresponding value as defined by entry's [Pair.second].
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JsName("containsPairs")
infix fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValuePairs: Pairs<K, V>)
infix fun <K, V, T: Map<out K, V>> Assert<T>.contains(keyValuePairs: Pairs<K, V>)
= addAssertion(AssertImpl.map.contains(this, keyValuePairs.toList()))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValuePair]'s [Pair.first]
* with a corresponding value as defined by [keyValuePair]'s [Pair.second].
*
* Delegates to `contains Pairs(entry)`.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline infix fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValuePair: Pair<K, V?>)
= this contains Pairs(keyValuePair)
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains for each entry in [keyValuePairs], a key as defined by
* entry's [Pair.first] with a corresponding value as defined by entry's [Pair.second].
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline infix fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValuePairs: Pairs<K, V?>)
= addAssertion(AssertImpl.map.containsNullable(this, V::class, keyValuePairs.toList()))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which holds all assertions [keyValue]'s [KeyValue.valueAssertionCreator] might create.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
infix fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValue: KeyValue<K, V, Assert<V>.() -> Unit>)
= contains(All(keyValue))
/**
* Makes the assertion that for each of the [KeyValue] in [keyValues], the [Assert.subject][AssertionPlant.subject] contains a key
* as defined by keyValue's [KeyValue.key] with a corresponding value which holds all assertions keyValues's
* [KeyValue.valueAssertionCreatorOrNull] might create.
*
* Notice, that it does not search for unique matches. Meaning, if the map is `mapOf('a' to 1)` and one of the
* [keyValues] is defined as `Key('a') { isGreaterThan(0) }` and another one is defined as `Key('a') { isLessThan(2) }`
* then both match, even though they match the same entry.
*
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
infix fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValues: All<KeyValue<K, V, Assert<V>.() -> Unit>>)
= addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, keyValues.toList().map { it.toPair() }))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains a key as defined by [keyValue]'s [KeyValue.key]
* with a corresponding value which either holds all assertions [keyValue]'s
@@ -96,8 +40,7 @@ infix fun <K, V : Any, T: Map<out K, V>> Assert<T>.contains(keyValues: All<KeyVa
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline infix fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValue: KeyValue<K, V, (Assert<V>.() -> Unit)?>)
infix fun <K, V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValue: KeyValue<K, V>)
= contains(All(keyValue))
/**
@@ -113,9 +56,8 @@ inline infix fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(keyV
* @return This plant to support a fluent API.
* @throws AssertionError Might throw an [AssertionError] if the assertion made is not correct.
*/
@JvmName("containsNullable")
inline infix fun <K, reified V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValues: All<KeyValue<K, V, (Assert<V>.() -> Unit)?>>)
= addAssertion(AssertImpl.map.containsKeyWithNullableValueAssertions(this, V::class, keyValues.toList().map { it.toPair() }))
infix fun <K, V : Any, T: Map<out K, V?>> Assert<T>.contains(keyValues: All<KeyValue<K, V>>)
= addAssertion(AssertImpl.map.containsKeyWithValueAssertions(this, keyValues.toList().map { it.toPair() }))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains the given [key].
@@ -136,7 +78,6 @@ infix fun <K> Assert<Map<out K, *>>.containsNotKey(key: K)
= addAssertion(AssertImpl.map.containsNotKey(this, key))
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject] contains the given [key], creates a feature
* assertion plant for the corresponding value and returns the newly created plant.
@@ -178,7 +119,6 @@ infix fun <K, V, T: Map<out K, V>> Assert<T>.getExisting(key: Key<K>): MapGetNul
= MapGetNullableOption.create(this, key.key)
/**
* Makes the assertion that the [Assert.subject][AssertionPlant.subject]'s [Map.size] is [size].
*

View File

@@ -68,8 +68,8 @@ data class Key<out K>(val key: K)
* Parameter object to express a key/value [Pair] whose value type is a lambda with an
* [Assert][AssertionPlant] receiver, which means one can either pass a lambda or `null`.
*/
data class KeyValue<out K, V : Any, A: ((Assert<V>) -> Unit)?>(val key: K, val valueAssertionCreatorOrNull: A) {
fun toPair(): Pair<K, A> = key to valueAssertionCreatorOrNull
data class KeyValue<out K, V : Any>(val key: K, val valueAssertionCreatorOrNull: (Assert<V>.() -> Unit)?) {
fun toPair(): Pair<K, (Assert<V>.() -> Unit)?> = key to valueAssertionCreatorOrNull
override fun toString(): String
= "KeyValue(key=$key, value=${if (valueAssertionCreatorOrNull == null) "null" else "lambda"})"
}

View File

@@ -4,6 +4,7 @@ import ch.tutteli.atrium.api.cc.infix.en_GB.keywords.Empty
import ch.tutteli.atrium.creating.Assert
import ch.tutteli.atrium.domain.builders.utils.mapArguments
import ch.tutteli.atrium.verbs.internal.AssertionVerbFactory
import ch.tutteli.atrium.verbs.internal.assert
import kotlin.reflect.KFunction2
class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
@@ -11,7 +12,7 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
containsFun.name to Companion::contains,
containsNullableFun.name to Companion::containsNullable,
"${containsKeyWithValueAssertionsFun.name} ${KeyValue::class.simpleName}" to Companion::containsKeyWithValueAssertions,
"${containsKeyWithNullableValueAssertionsFun.name} ${KeyNullableValue::class.simpleName}" to Companion::containsKeyWithNullableValueAssertions,
"${containsKeyWithNullableValueAssertionsFun.name} ${KeyValue::class.simpleName}" to Companion::containsKeyWithNullableValueAssertions,
Assert<Map<out String, Int>>::containsKey.name to Companion::containsKey,
Assert<Map<out String?, *>>::containsKey.name to Companion::containsNullableKey,
Assert<Map<out String, Int>>::containsNotKey.name to Companion::containsNotKey,
@@ -39,7 +40,7 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
}
}
private val containsKeyWithValueAssertionsFun : KFunction2<Assert<Map<out String, Int>>, KeyValue<String, Int, Assert<Int>.() -> Unit>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::contains
private val containsKeyWithValueAssertionsFun : KFunction2<Assert<Map<out String, Int>>, KeyValue<String, Int>, Assert<Map<out String, Int>>> = Assert<Map<out String, Int>>::contains
private fun containsKeyWithValueAssertions(plant: Assert<Map<out String, Int>>, keyValue: Pair<String, Assert<Int>.() -> Unit>, otherKeyValues: Array<out Pair<String, Assert<Int>.() -> Unit>>) : Assert<Map<out String, Int>> {
return if (otherKeyValues.isEmpty()) {
plant contains KeyValue(keyValue.first, keyValue.second)
@@ -50,7 +51,7 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
}
}
private val containsKeyWithNullableValueAssertionsFun : KFunction2<Assert<Map<out String?, Int?>>, KeyValue<String, Int, (Assert<Int>.() -> Unit)?>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::contains
private val containsKeyWithNullableValueAssertionsFun : KFunction2<Assert<Map<out String?, Int?>>, KeyValue<String, Int>, Assert<Map<out String?, Int?>>> = Assert<Map<out String?, Int?>>::contains
private fun containsKeyWithNullableValueAssertions(plant: Assert<Map<out String?, Int?>>, keyValue: Pair<String?, (Assert<Int>.() -> Unit)?>, otherKeyValues: Array<out Pair<String?, (Assert<Int>.() -> Unit)?>>): Assert<Map<out String?, Int?>> {
return if (otherKeyValues.isEmpty()) {
plant contains KeyValue(keyValue.first, keyValue.second)
@@ -82,5 +83,66 @@ class MapAssertionsSpec : ch.tutteli.atrium.spec.integration.MapAssertionsSpec(
private fun isNotEmpty(plant: Assert<Map<*, *>>)
= plant notToBe Empty
}
@Suppress("unused")
private fun ambiguityTest() {
val map = mapOf(1 to "a")
val nullableKeyMap = mapOf(1 as Int? to "a")
val nullableValueMap = mapOf(1 to "a" as String?)
val nullableKeyValueMap = mapOf(1 as Int? to "a" as String?)
assert(map) contains (1 to "a")
assert(map) contains Pairs(1 to "a", 2 to "b")
assert(map) contains KeyValue(1){}
assert(map) contains All(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyMap) contains (1 to "a")
assert(nullableKeyMap) contains Pairs(1 to "a", 2 to "b")
assert(nullableKeyMap) contains KeyValue(1){}
assert(nullableKeyMap) contains All(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyMap) contains (null to "a")
assert(nullableKeyMap) contains Pairs(null to "a", null to "b")
assert(nullableKeyMap) contains Pairs(null to "a", 2 to "b")
assert(nullableKeyMap) contains KeyValue(null){}
assert(nullableKeyMap) contains All(KeyValue(null){}, KeyValue(null){})
assert(nullableKeyMap) contains All(KeyValue(null){}, KeyValue(2){})
assert(nullableValueMap) contains (1 to "a")
assert(nullableValueMap) contains Pairs(1 to "a", 2 to "b")
assert(nullableValueMap) contains KeyValue(1){}
assert(nullableValueMap) contains All(KeyValue(1){}, KeyValue(2){})
assert(nullableValueMap) contains (1 to null)
assert(nullableValueMap) contains Pairs(1 to null, 2 to null)
assert(nullableValueMap) contains Pairs(1 to null, 2 to "a")
assert(nullableValueMap) contains KeyValue(1, null)
assert(nullableValueMap) contains All(KeyValue(1, null), KeyValue(2, null))
assert(nullableValueMap) contains All(KeyValue(1, null), KeyValue(2){})
assert(nullableKeyValueMap) contains (1 to "a")
assert(nullableKeyValueMap) contains Pairs(1 to "a", 2 to "b")
assert(nullableKeyValueMap) contains All(KeyValue(1){})
assert(nullableKeyValueMap) contains All(KeyValue(1){}, KeyValue(2){})
assert(nullableKeyValueMap) contains (null to "a")
assert(nullableKeyValueMap) contains Pairs(null to "a", null to "b")
assert(nullableKeyValueMap) contains Pairs(null to "a", 2 to "b")
assert(nullableKeyValueMap) contains KeyValue(null){}
assert(nullableKeyValueMap) contains All(KeyValue(null){}, KeyValue(null){})
assert(nullableKeyValueMap) contains All(KeyValue(null){}, KeyValue(2){})
assert(nullableKeyValueMap) contains (1 to null)
assert(nullableKeyValueMap) contains Pairs(1 to null, 2 to null)
assert(nullableKeyValueMap) contains Pairs(1 to null, 2 to "a")
assert(nullableKeyValueMap) contains KeyValue(1, null)
assert(nullableKeyValueMap) contains All(KeyValue(1, null), KeyValue(2, null))
assert(nullableKeyValueMap) contains All(KeyValue(1, null), KeyValue(2){})
//TODO don't use Pair but null to null as soon as https://youtrack.jetbrains.com/issue/KT-30496 is fiex
assert(nullableKeyValueMap) contains Pair(null, null)
assert(nullableKeyValueMap) contains Pairs(Pair(null, null), null to null as String?)
assert(nullableKeyValueMap) contains Pairs(1 to null, null to "a")
assert(nullableKeyValueMap) contains KeyValue(null, null)
assert(nullableKeyValueMap) contains All(KeyValue(null, null), KeyValue(null, null))
assert(nullableKeyValueMap) contains All(KeyValue(1, null), KeyValue(null){})
}
}

View File

@@ -5,7 +5,6 @@ import ch.tutteli.atrium.core.polyfills.loadSingleService
import ch.tutteli.atrium.creating.Assert
import ch.tutteli.atrium.creating.AssertionPlant
import ch.tutteli.atrium.creating.AssertionPlantNullable
import kotlin.reflect.KClass
/**
* The access point to an implementation of [MapAssertions].
@@ -20,10 +19,8 @@ val mapAssertions by lazy { loadSingleService(MapAssertions::class) }
* which an implementation of the domain of Atrium has to provide.
*/
interface MapAssertions {
fun <K, V: Any> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>): Assertion
fun <K, V: Any> containsNullable(plant: AssertionPlant<Map<out K, V?>>, type: KClass<V>, keyValuePairs: List<Pair<K, V?>>): Assertion
fun <K, V: Any> containsKeyWithValueAssertions(plant: AssertionPlant<Map<out K, V>>, keyValues: List<Pair<K, Assert<V>.() -> Unit>>): Assertion
fun <K, V: Any> containsKeyWithNullableValueAssertions(plant: AssertionPlant<Map<out K, V?>>, type: KClass<V>, keyValues: List<Pair<K, (Assert<V>.() -> Unit)?>>): Assertion
fun <K, V> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>): Assertion
fun <K, V: Any> containsKeyWithValueAssertions(plant: AssertionPlant<Map<out K, V?>>, keyValues: List<Pair<K, (Assert<V>.() -> Unit)?>>): Assertion
fun <K> containsKey(plant: AssertionPlant<Map<out K, *>>, key: K): Assertion
fun <K> containsNotKey(plant: AssertionPlant<Map<out K, *>>, key: K): Assertion

View File

@@ -9,7 +9,6 @@ import ch.tutteli.atrium.creating.AssertionPlantNullable
import ch.tutteli.atrium.domain.creating.MapAssertions
import ch.tutteli.atrium.domain.creating.MapEntryAssertions
import ch.tutteli.atrium.domain.creating.mapAssertions
import kotlin.reflect.KClass
/**
* Delegates inter alia to the implementation of [MapAssertions].
@@ -24,22 +23,13 @@ object MapAssertionsBuilder : MapAssertions {
*/
inline val entry get() : MapEntryAssertionsBuilder = MapEntryAssertionsBuilder
override inline fun <K, V: Any> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>): Assertion
override inline fun <K, V> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>): Assertion
= mapAssertions.contains(plant, keyValuePairs)
override inline fun <K, V: Any> containsNullable(plant: AssertionPlant<Map<out K, V?>>, type: KClass<V>, keyValuePairs: List<Pair<K, V?>>): Assertion
= mapAssertions.containsNullable(plant, type, keyValuePairs)
override inline fun <K, V : Any> containsKeyWithValueAssertions(
plant: AssertionPlant<Map<out K, V>>,
keyValues: List<Pair<K, Assert<V>.() -> Unit>>
) = mapAssertions.containsKeyWithValueAssertions(plant, keyValues)
override inline fun <K, V : Any> containsKeyWithNullableValueAssertions(
plant: AssertionPlant<Map<out K, V?>>,
type: KClass<V>,
keyValues: List<Pair<K, (Assert<V>.() -> Unit)?>>
) = mapAssertions.containsKeyWithNullableValueAssertions(plant, type, keyValues)
) = mapAssertions.containsKeyWithValueAssertions(plant, keyValues)
override inline fun <K> containsKey(plant: AssertionPlant<Map<out K, *>>, key: K)
= mapAssertions.containsKey(plant, key)

View File

@@ -3,8 +3,10 @@ package ch.tutteli.atrium.domain.robstoll.lib.creating
import ch.tutteli.atrium.api.cc.en_GB.property
import ch.tutteli.atrium.api.cc.en_GB.toBe
import ch.tutteli.atrium.assertions.Assertion
import ch.tutteli.atrium.core.trueProvider
import ch.tutteli.atrium.creating.*
import ch.tutteli.atrium.domain.builders.AssertImpl
import ch.tutteli.atrium.domain.builders.utils.subAssert
import ch.tutteli.atrium.domain.creating.feature.extract.FeatureExtractor
import ch.tutteli.atrium.domain.robstoll.lib.assertions.LazyThreadUnsafeAssertionGroup
import ch.tutteli.atrium.reporting.RawString
@@ -12,42 +14,39 @@ import ch.tutteli.atrium.reporting.translating.TranslatableWithArgs
import ch.tutteli.atrium.translations.DescriptionBasic
import ch.tutteli.atrium.translations.DescriptionCollectionAssertion.EMPTY
import ch.tutteli.atrium.translations.DescriptionMapAssertion
import kotlin.reflect.KClass
fun <K, V : Any> _contains(plant: AssertionPlant<Map<out K, V>>, pairs: List<Pair<K, V>>): Assertion
= containsNonNullable(plant, pairs) { value -> toBe(value) }
fun <K, V : Any> _containsNullable(
plant: AssertionPlant<Map<out K, V?>>,
type: KClass<V>,
pairs: List<Pair<K, V?>>
): Assertion = containsNullable(plant, pairs) { value ->
addAssertion(AssertImpl.any.isNullable(this, type, value))
}
fun <K, V> _contains(
plant: AssertionPlant<Map<out K, V>>,
pairs: List<Pair<K, V>>
): Assertion = _containsKeyWithValueAssertion<K, Any>(plant, pairs.map {
it.first to it.second?.let { expected -> subAssert<Any> { toBe(expected as Any) } }
})
fun <K, V : Any> _containsKeyWithValueAssertion(
plant: AssertionPlant<Map<out K, V>>,
keyValues: List<Pair<K, Assert<V>.() -> Unit>>
): Assertion = containsNonNullable(plant, keyValues.map { it }) { assertionCreator -> assertionCreator() }
fun <K, V : Any> _containsKeyWithNullableValueAssertions(
plant: AssertionPlant<Map<out K, V?>>,
type: KClass<V>,
keyValues: List<Pair<K, (Assert<V>.() -> Unit)?>>
): Assertion = containsNullable(plant, keyValues.map{ it }) { assertionCreator ->
addAssertion(AssertImpl.any.isNullIfNullGivenElse(this, type, assertionCreator))
val subjectIsNull = try {
this.subject == null
} catch (t: PlantHasNoSubjectException) {
true
}
if (assertionCreator != null && !subjectIsNull) {
AssertImpl.changeSubject(this) { this.subject as V }.assertionCreator()
} else if (subjectIsNull && assertionCreator == null){
addAssertion(AssertImpl.builder.createDescriptive(DescriptionBasic.IS, RawString.NULL, trueProvider))
} else {
addAssertion(AssertImpl.builder.explanatoryGroup
.withDefaultType
.withAssertions(AssertImpl.collector.forExplanation.throwIfNoAssertionIsCollected.collect(
DescriptionMapAssertion.CANNOT_EVALUATE_KEY_DOES_NOT_EXIST,
MaybeSubject.Absent,
assertionCreator)
)
.build())
}
}
private fun <K, V : Any, M> containsNonNullable(
plant: AssertionPlant<Map<out K, V>>,
pairs: List<Pair<K, M>>,
assertionCreator: AssertionPlant<V>.(M) -> Unit
) = contains(
pairs,
{ option, key -> option.withParameterObject(createGetParameterObject(plant, key)) },
assertionCreator
)
private fun <K, V : Any, M> containsNullable(
plant: AssertionPlant<Map<out K, V?>>,
pairs: List<Pair<K, M>>,

View File

@@ -6,32 +6,19 @@ import ch.tutteli.atrium.creating.AssertionPlant
import ch.tutteli.atrium.creating.AssertionPlantNullable
import ch.tutteli.atrium.domain.creating.MapAssertions
import ch.tutteli.atrium.domain.robstoll.lib.creating.*
import kotlin.reflect.KClass
/**
* Robstoll's implementation of [MapAssertions].
*/
class MapAssertionsImpl : MapAssertions {
override fun <K, V: Any> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>)
override fun <K, V> contains(plant: AssertionPlant<Map<out K, V>>, keyValuePairs: List<Pair<K, V>>)
= _contains(plant, keyValuePairs)
override fun <K, V: Any> containsNullable(
plant: AssertionPlant<Map<out K, V?>>,
type: KClass<V>,
keyValuePairs: List<Pair<K, V?>>
) = _containsNullable(plant, type, keyValuePairs)
override fun <K, V : Any> containsKeyWithValueAssertions(
plant: AssertionPlant<Map<out K, V>>,
keyValues: List<Pair<K, Assert<V>.() -> Unit>>
) = _containsKeyWithValueAssertion(plant, keyValues)
override fun <K, V : Any> containsKeyWithNullableValueAssertions(
plant: AssertionPlant<Map<out K, V?>>,
type: KClass<V>,
keyValues: List<Pair<K, (Assert<V>.() -> Unit)?>>
) = _containsKeyWithNullableValueAssertions(plant, type, keyValues)
) = _containsKeyWithValueAssertion(plant, keyValues)
override fun <K> containsKey(plant: AssertionPlant<Map<out K, *>>, key: K)
= _containsKey(plant, key)