From cfe0918b3b7e01fc46f669e444c2e637c95ff571 Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Tue, 18 May 2021 14:07:03 +0200 Subject: [PATCH] deprecate mapAssertions, use mew ...Expectations in api-fluent --- README.md | 12 ++--- .../atrium/api/fluent/en_GB/mapAssertions.kt | 49 ++++++++++++++++--- .../en_GB/samples/MapExpectationSamples.kt | 8 +-- .../readme/examples/MostExamplesSpec.kt | 12 ++--- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index db03f2ba2..d29c67e35 100644 --- a/README.md +++ b/README.md @@ -1285,7 +1285,7 @@ and more [Sophisticated Assertion Builder](#sophisticated-assertion-builders-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) ``` ↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L167)[Output](#ex-map-1) @@ -1305,7 +1305,7 @@ the help of the parameter object `KeyValue`: ```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: ```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) ``` ↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L178)[Output](#ex-map-only-1) @@ -1352,7 +1352,7 @@ And the other overload which expects a `KeyValue` and allows defining sub aserti ```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: ```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) ``` ↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L189)[Output](#ex-map-builder-1) @@ -1409,7 +1409,7 @@ And the other expecting `KeyValue`s which allow specifying sub assertions for th ```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) }) ``` diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapAssertions.kt index 3df2fbb23..3930a0215 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapAssertions.kt @@ -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 > Expect.contains: MapLikeContains.EntryPointStep get() = _logic.builderContainsInMapLike(::identity) @@ -33,10 +34,14 @@ val > Expect.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(keyValuePair, *otherPairs)") +) fun > Expect.contains( keyValuePair: Pair, vararg otherPairs: Pair -): Expect = contains.inAnyOrder.entries(keyValuePair, *otherPairs) +): Expect = 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 > Expect.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(keyValuePair, *otherPairs)") +) fun > Expect.containsOnly( keyValuePair: Pair, vararg otherPairs: Pair -): Expect = contains.inAnyOrder.only.entries(keyValuePair, *otherPairs) +): Expect = 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 > Expect.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(keyValue, *otherKeyValues)") +) inline fun > Expect.contains( keyValue: KeyValue, vararg otherKeyValues: KeyValue -): Expect = contains.inAnyOrder.entries(keyValue, *otherKeyValues) +): Expect = 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 > Expect.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(keyValue, *otherKeyValues)") +) inline fun > Expect.containsOnly( keyValue: KeyValue, vararg otherKeyValues: KeyValue -): Expect = contains.inAnyOrder.only.entries(keyValue, *otherKeyValues) +): Expect = 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 > Expect.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(mapLike)") +) fun > Expect.containsEntriesOf( mapLike: MapLike -): Expect = contains.inAnyOrder.entriesOf(mapLike) +): Expect = 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 > Expect.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(mapLike)") +) fun > Expect.containsOnlyEntriesOf( mapLike: MapLike -): Expect = contains.inAnyOrder.only.entriesOf(mapLike) +): Expect = toContain.inAnyOrder.only.entriesOf(mapLike) /** * Expects that the subject of `this` expectation (a [Map]) contains the given [key]. @@ -128,6 +153,10 @@ fun > Expect.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(key)") +) fun > Expect.containsKey(key: K): Expect = _logicAppend { containsKey(::identity, key) } @@ -138,6 +167,10 @@ fun > Expect.containsKey(key: K): Expect = * * @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(key)") +) fun > Expect.containsNotKey(key: K): Expect = _logicAppend { containsNotKey(::identity, key) } @@ -253,6 +286,7 @@ fun > Expect.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()")) fun > Expect.isEmpty(): Expect = _logicAppend { isEmpty(::toEntries) } @@ -263,6 +297,7 @@ fun > Expect.isEmpty(): Expect = * * @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()")) fun > Expect.isNotEmpty(): Expect = _logicAppend { isNotEmpty(::toEntries) } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapExpectationSamples.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapExpectationSamples.kt index 3a19bb023..975224026 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapExpectationSamples.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapExpectationSamples.kt @@ -237,19 +237,19 @@ class MapExpectationSamples { @Test fun toBeEmpty() { - expect(emptyMap()).isEmpty() + expect(emptyMap()).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()).isNotEmpty() + expect(emptyMap()).notToBeEmpty() } } } diff --git a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt index b81997bdd..462e9aaad 100644 --- a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt +++ b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt @@ -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) }) }