mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
deprecate mapAssertions, use mew ...Expectations in api-fluent
This commit is contained in:
12
README.md
12
README.md
@@ -1285,7 +1285,7 @@ and more [Sophisticated Assertion Builder](#sophisticated-assertion-builders-1)
|
||||
<ex-map-1>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains("c" to 2, "a" to 1, "b" to 1)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain("c" to 2, "a" to 1, "b" to 1)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L167)</sub> ↓ <sub>[Output](#ex-map-1)</sub>
|
||||
<a name="ex-map-1"></a>
|
||||
@@ -1305,7 +1305,7 @@ the help of the parameter object `KeyValue`:
|
||||
<ex-map-2>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain(
|
||||
KeyValue("c") { toEqual(2) },
|
||||
KeyValue("a") { toBeGreaterThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
@@ -1331,7 +1331,7 @@ Again both overloads are provided, one for key-value `Pair`s:
|
||||
<ex-map-only-1>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).containsOnly("b" to 2)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContainOnly("b" to 2)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L178)</sub> ↓ <sub>[Output](#ex-map-only-1)</sub>
|
||||
<a name="ex-map-only-1"></a>
|
||||
@@ -1352,7 +1352,7 @@ And the other overload which expects a `KeyValue` and allows defining sub aserti
|
||||
<ex-map-only-2>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).containsOnly(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContainOnly(
|
||||
KeyValue("c") { toEqual(2) },
|
||||
KeyValue("a") { toBeLessThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
@@ -1384,7 +1384,7 @@ again provide two overloads, one expecting key-value `Pair`s:
|
||||
<ex-map-builder-1>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries("b" to 2, "a" to 1)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries("b" to 2, "a" to 1)
|
||||
```
|
||||
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L189)</sub> ↓ <sub>[Output](#ex-map-builder-1)</sub>
|
||||
<a name="ex-map-builder-1"></a>
|
||||
@@ -1409,7 +1409,7 @@ And the other expecting `KeyValue`s which allow specifying sub assertions for th
|
||||
<ex-map-builder-2>
|
||||
|
||||
```kotlin
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries(
|
||||
KeyValue("a") { toBeLessThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) })
|
||||
```
|
||||
|
||||
@@ -14,6 +14,7 @@ import ch.tutteli.kbox.identity
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsBuilder
|
||||
*/
|
||||
@Deprecated("Use toContain; will be removed with 1.0.0 at the latest", ReplaceWith("this.toContain"))
|
||||
val <K, V, T : Map<out K, V>> Expect<T>.contains: MapLikeContains.EntryPointStep<K, V, T, NoOpSearchBehaviour>
|
||||
get() = _logic.builderContainsInMapLike(::identity)
|
||||
|
||||
@@ -33,10 +34,14 @@ val <K, V, T : Map<out K, V>> Expect<T>.contains: MapLikeContains.EntryPointStep
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsPair
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContain; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContain<K, V, T>(keyValuePair, *otherPairs)")
|
||||
)
|
||||
fun <K, V, T : Map<out K, V>> Expect<T>.contains(
|
||||
keyValuePair: Pair<K, V>,
|
||||
vararg otherPairs: Pair<K, V>
|
||||
): Expect<T> = contains.inAnyOrder.entries(keyValuePair, *otherPairs)
|
||||
): Expect<T> = toContain.inAnyOrder.entries(keyValuePair, *otherPairs)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains only (in any order) a key as defined by
|
||||
@@ -47,12 +52,16 @@ fun <K, V, T : Map<out K, V>> Expect<T>.contains(
|
||||
*
|
||||
* @return an [Expect] for the subject of `this` expectation.
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsOnly
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsOnlyPair
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContainOnly; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContainOnly<K, V, T>(keyValuePair, *otherPairs)")
|
||||
)
|
||||
fun <K, V, T : Map<out K, V>> Expect<T>.containsOnly(
|
||||
keyValuePair: Pair<K, V>,
|
||||
vararg otherPairs: Pair<K, V>
|
||||
): Expect<T> = contains.inAnyOrder.only.entries(keyValuePair, *otherPairs)
|
||||
): Expect<T> = toContain.inAnyOrder.only.entries(keyValuePair, *otherPairs)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains a key as defined by [keyValue]'s [KeyValue.key]
|
||||
@@ -71,10 +80,14 @@ fun <K, V, T : Map<out K, V>> Expect<T>.containsOnly(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsKeyValue
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContain; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContain<K, V, T>(keyValue, *otherKeyValues)")
|
||||
)
|
||||
inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(
|
||||
keyValue: KeyValue<K, V>,
|
||||
vararg otherKeyValues: KeyValue<K, V>
|
||||
): Expect<T> = contains.inAnyOrder.entries(keyValue, *otherKeyValues)
|
||||
): Expect<T> = toContain.inAnyOrder.entries(keyValue, *otherKeyValues)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains only (in any order) a key as defined by
|
||||
@@ -89,10 +102,14 @@ inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.contains(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsOnlyKeyValue
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContainOnly; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContainOnly<K, V, T>(keyValue, *otherKeyValues)")
|
||||
)
|
||||
inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.containsOnly(
|
||||
keyValue: KeyValue<K, V>,
|
||||
vararg otherKeyValues: KeyValue<K, V>
|
||||
): Expect<T> = contains.inAnyOrder.only.entries(keyValue, *otherKeyValues)
|
||||
): Expect<T> = toContain.inAnyOrder.only.entries(keyValue, *otherKeyValues)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains the key-value pairs of the given [mapLike].
|
||||
@@ -103,9 +120,13 @@ inline fun <K, reified V : Any, T : Map<out K, V?>> Expect<T>.containsOnly(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsEntriesOf
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContainEntriesOf; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContainEntriesOf<K, V, T>(mapLike)")
|
||||
)
|
||||
fun <K, V : Any, T : Map<out K, V?>> Expect<T>.containsEntriesOf(
|
||||
mapLike: MapLike
|
||||
): Expect<T> = contains.inAnyOrder.entriesOf(mapLike)
|
||||
): Expect<T> = toContain.inAnyOrder.entriesOf(mapLike)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains only (in any order) the key-value pairs of
|
||||
@@ -117,9 +138,13 @@ fun <K, V : Any, T : Map<out K, V?>> Expect<T>.containsEntriesOf(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsOnlyEntriesOf
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContainOnlyEntriesOf; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContainOnlyEntriesOf<K, V, T>(mapLike)")
|
||||
)
|
||||
fun <K, V : Any, T : Map<out K, V?>> Expect<T>.containsOnlyEntriesOf(
|
||||
mapLike: MapLike
|
||||
): Expect<T> = contains.inAnyOrder.only.entriesOf(mapLike)
|
||||
): Expect<T> = toContain.inAnyOrder.only.entriesOf(mapLike)
|
||||
|
||||
/**
|
||||
* Expects that the subject of `this` expectation (a [Map]) contains the given [key].
|
||||
@@ -128,6 +153,10 @@ fun <K, V : Any, T : Map<out K, V?>> Expect<T>.containsOnlyEntriesOf(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsKey
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use toContainKey; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.toContainKey<K, T>(key)")
|
||||
)
|
||||
fun <K, T : Map<out K, *>> Expect<T>.containsKey(key: K): Expect<T> =
|
||||
_logicAppend { containsKey(::identity, key) }
|
||||
|
||||
@@ -138,6 +167,10 @@ fun <K, T : Map<out K, *>> Expect<T>.containsKey(key: K): Expect<T> =
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.containsNotKey
|
||||
*/
|
||||
@Deprecated(
|
||||
"Use notToContainKey; will be removed with 1.0.0 at the latest",
|
||||
ReplaceWith("this.notToContainKey<K, T>(key)")
|
||||
)
|
||||
fun <K, T : Map<out K, *>> Expect<T>.containsNotKey(key: K): Expect<T> =
|
||||
_logicAppend { containsNotKey(::identity, key) }
|
||||
|
||||
@@ -253,6 +286,7 @@ fun <K, V, T : Map<out K, V>> Expect<T>.asEntries(
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.isEmpty
|
||||
*/
|
||||
@Deprecated("Use toBeEmpty; will be removed with 1.0.0 at the latest", ReplaceWith("this.toBeEmpty<T>()"))
|
||||
fun <T : Map<*, *>> Expect<T>.isEmpty(): Expect<T> =
|
||||
_logicAppend { isEmpty(::toEntries) }
|
||||
|
||||
@@ -263,6 +297,7 @@ fun <T : Map<*, *>> Expect<T>.isEmpty(): Expect<T> =
|
||||
*
|
||||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.isNotEmpty
|
||||
*/
|
||||
@Deprecated("Use notToBeEmpty; will be removed with 1.0.0 at the latest", ReplaceWith("this.notToBeEmpty<T>()"))
|
||||
fun <T : Map<*, *>> Expect<T>.isNotEmpty(): Expect<T> =
|
||||
_logicAppend { isNotEmpty(::toEntries) }
|
||||
|
||||
|
||||
@@ -237,19 +237,19 @@ class MapExpectationSamples {
|
||||
|
||||
@Test
|
||||
fun toBeEmpty() {
|
||||
expect(emptyMap<Int, String>()).isEmpty()
|
||||
expect(emptyMap<Int, String>()).toBeEmpty()
|
||||
|
||||
fails { // because the map is not empty
|
||||
expect(mapOf(1 to "a")).isEmpty()
|
||||
expect(mapOf(1 to "a")).toBeEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun notToBeEmpty() {
|
||||
expect(mapOf(1 to "a")).isNotEmpty()
|
||||
expect(mapOf(1 to "a")).notToBeEmpty()
|
||||
|
||||
fails { // because the map is empty
|
||||
expect(emptyMap<Int, String>()).isNotEmpty()
|
||||
expect(emptyMap<Int, String>()).notToBeEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,10 +165,10 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
|
||||
test("ex-map-1") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains("c" to 2, "a" to 1, "b" to 1)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain("c" to 2, "a" to 1, "b" to 1)
|
||||
}
|
||||
test("ex-map-2") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain(
|
||||
KeyValue("c") { toEqual(2) },
|
||||
KeyValue("a") { toBeGreaterThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
@@ -176,10 +176,10 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
|
||||
test("ex-map-only-1") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).containsOnly("b" to 2)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContainOnly("b" to 2)
|
||||
}
|
||||
test("ex-map-only-2") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).containsOnly(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContainOnly(
|
||||
KeyValue("c") { toEqual(2) },
|
||||
KeyValue("a") { toBeLessThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) }
|
||||
@@ -187,10 +187,10 @@ class MostExamplesSpec : Spek({
|
||||
}
|
||||
|
||||
test("ex-map-builder-1") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries("b" to 2, "a" to 1)
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries("b" to 2, "a" to 1)
|
||||
}
|
||||
test("ex-map-builder-2") {
|
||||
expect(mapOf("a" to 1, "b" to 2)).contains.inOrder.only.entries(
|
||||
expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries(
|
||||
KeyValue("a") { toBeLessThan(2) },
|
||||
KeyValue("b") { toBeLessThan(2) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user