From 37b8749566b09b47b19d39fab26a2bfef97f97c8 Mon Sep 17 00:00:00 2001 From: Bacho Kurtanidze <39156859+kacmacuna@users.noreply.github.com> Date: Mon, 31 May 2021 14:08:22 +0400 Subject: [PATCH] add MapEntyAssertionSamples in infix package (#911) --- .../api/infix/en_GB/mapEntryAssertions.kt | 8 ++ .../api/infix/en_GB/mapEntryExpectations.kt | 2 + .../samples/MapEntryExpectationSamples.kt | 90 +++++++++++++++++++ .../deprecated/MapEntryAssertionSamples.kt | 56 ++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/MapEntryExpectationSamples.kt create mode 100644 apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/deprecated/MapEntryAssertionSamples.kt diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryAssertions.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryAssertions.kt index 59f638aaa..ebf36cbb2 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryAssertions.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryAssertions.kt @@ -22,6 +22,8 @@ infix fun > Expect.isKeyValue(keyValuePair: Pair> Expect.key: Expect @@ -33,6 +35,8 @@ val > Expect.key: Expect * holds all assertions the given [assertionCreator] creates for it and * returns an [Expect] for the current subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.key + * * @return an [Expect] for the subject of `this` expectation. */ infix fun > Expect.key(assertionCreator: Expect.() -> Unit): Expect = @@ -43,6 +47,8 @@ infix fun > Expect.key(assertionCreator: Expect. * Creates an [Expect] for the property [Map.Entry.value] of the subject of `this` expectation, * so that further fluent calls are assertions about it. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.valueFeature + * * @return The newly created [Expect] for the extracted feature. */ val > Expect.value: Expect @@ -54,6 +60,8 @@ val > Expect.value: Expect * holds all assertions the given [assertionCreator] creates for it and * returns an [Expect] for the current subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.value + * * @return an [Expect] for the subject of `this` expectation. */ infix fun > Expect.value(assertionCreator: Expect.() -> Unit): Expect = diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryExpectations.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryExpectations.kt index b4a92a11e..588f4c3f7 100644 --- a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryExpectations.kt +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/infix/en_GB/mapEntryExpectations.kt @@ -9,6 +9,8 @@ import ch.tutteli.atrium.logic.* * * @return an [Expect] for the subject of `this` expectation. * + * @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.toEqualKeyValue + * * @since 0.17.0 */ infix fun > Expect.toEqualKeyValue(keyValuePair: Pair): Expect = diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/MapEntryExpectationSamples.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/MapEntryExpectationSamples.kt new file mode 100644 index 000000000..e7e6fadf5 --- /dev/null +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/MapEntryExpectationSamples.kt @@ -0,0 +1,90 @@ +package ch.tutteli.atrium.api.infix.en_GB.samples + +import ch.tutteli.atrium.api.infix.en_GB.key +import ch.tutteli.atrium.api.infix.en_GB.toEqual +import ch.tutteli.atrium.api.infix.en_GB.toEqualKeyValue +import ch.tutteli.atrium.api.infix.en_GB.value +import ch.tutteli.atrium.api.verbs.internal.expect +import kotlin.test.Test + +class MapEntryExpectationSamples { + + @Test + fun toEqualKeyValue() { + expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "a") + // | | | subject here is type of Map.Entry (actually (1 to "a")) + // | | subject here is type of Set> + // | subject here is type of Map + + fails { + // fails because (1 to "a") is not equal to (1 to "b") + expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "b") + // | | | subject here is type of Map.Entry (actually (1 to "a")) + // | | subject here is type of Set> + // | subject here is type of Map + } + } + + @Test + fun keyFeature() { + expect(mapOf(1 to "a").entries.first()).key toEqual 1 + // | | subject here is type of Int (actually 1) + // | subject here is of type Map + + fails { + + // fails because 1 is not equal to 2 + expect(mapOf(1 to "a").entries.first()).key toEqual 2 + // | | subject here is type of Int (actually 1) + // | subject here is of type Map + } + } + + @Test + fun key() { + // | subject here is of type Map + expect(mapOf(1 to "a").entries.first()).key { // subject inside this block is of type Int (actually 1) + this toEqual 1 + } + + fails { + // fails because 1 is not equal to 2 + // | subject here is of type Map + expect(mapOf(1 to "a").entries.first()).key { // subject inside this block is of type Int (actually 1) + this toEqual 2 + } + } + } + + @Test + fun valueFeature() { + expect(mapOf(1 to "a").entries.first()).value toEqual "a" + // | | subject here is of type String (actually "a") + // | subject here is of type Map + + fails { + + // fails because "a" is not equal to "b" + expect(mapOf(1 to "a").entries.first()).value toEqual "b" + // | | subject here is of type String (actually "a") + // | subject here is of type Map + } + } + + @Test + fun value() { + // | subject here is of type Map + expect(mapOf(1 to "a").entries.first()) value { // subject inside this block is of type String (actually "a") + this toEqual "a" + } + + fails { + + // fails because "a" is not equal to "b" + // | subject here is of type Map + expect(mapOf(1 to "a").entries.first()) value { // subject inside this block is of type String (actually "a") + this toEqual "b" + } + } + } +} diff --git a/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/deprecated/MapEntryAssertionSamples.kt b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/deprecated/MapEntryAssertionSamples.kt new file mode 100644 index 000000000..15fff4830 --- /dev/null +++ b/apis/infix-en_GB/atrium-api-infix-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/infix/en_GB/samples/deprecated/MapEntryAssertionSamples.kt @@ -0,0 +1,56 @@ +package ch.tutteli.atrium.api.infix.en_GB.samples.deprecated + +import ch.tutteli.atrium.api.infix.en_GB.* +import ch.tutteli.atrium.api.infix.en_GB.samples.fails +import ch.tutteli.atrium.api.verbs.internal.expect +import kotlin.test.Test + +class MapEntryAssertionSamples { + + @Test + fun isKeyValue() { + expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "a") + + fails { + expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "b") + } + } + + @Test + fun keyFeature() { + expect(mapOf(1 to "a").entries.first()).key toEqual 1 + + fails { + expect(mapOf(1 to "a").entries.first()).key toEqual 2 + } + } + + @Test + fun key() { + expect(mapOf(1 to "a").entries.first()) key { it toEqual 1 } + + fails { + expect(mapOf(1 to "a").entries.first()) key { it toEqual 2 } + } + } + + @Test + fun valueFeature() { + expect(mapOf(1 to "a").entries.first()).value toEqual "a" + + fails { + expect(mapOf(1 to "a").entries.first()).value toEqual "b" + } + } + + @Test + fun value() { + expect(mapOf(1 to "a").entries.first()) value { it toEqual "a" } + + + fails { + expect(mapOf(1 to "a").entries.first()) value { it toEqual "b" } + } + } + +}