From 2e0e25d2ab8bd5c0d17b68e7fa16c1e464c3f1cf Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Wed, 19 May 2021 12:40:54 +0200 Subject: [PATCH] rename mapEntryAssertion functions to new schema in api-fluent --- .../atrium/api/fluent/en_GB/mapAssertions.kt | 16 ++-- .../en_GB/mapCollectionLikeAssertions.kt | 1 + .../api/fluent/en_GB/mapEntryAssertions.kt | 13 +++- .../api/fluent/en_GB/mapEntryExpectations.kt | 17 +++++ .../fluent/en_GB/MapEntryExpectationsSpec.kt | 4 +- .../samples/MapEntryExpectationSamples.kt | 73 +++++++++++++++++++ .../integration/MapEntryExpectationsSpec.kt | 30 ++++---- 7 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryExpectations.kt create mode 100644 apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapEntryExpectationSamples.kt 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 3930a0215..419fa1631 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 @@ -182,7 +182,7 @@ fun > Expect.containsNotKey(key: K): Expect = * * @return The newly created [Expect] for the extracted feature. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.getExistingFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.getExistingFeature */ fun > Expect.getExisting(key: K): Expect = _logic.getExisting(::identity, key).transform() @@ -194,7 +194,7 @@ fun > Expect.getExisting(key: K): Expect = * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.getExisting + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.getExisting */ fun > Expect.getExisting(key: K, assertionCreator: Expect.() -> Unit): Expect = _logic.getExisting(::identity, key).collectAndAppend(assertionCreator) @@ -206,7 +206,7 @@ fun > Expect.getExisting(key: K, assertionCreator: Ex * * @return The newly created [Expect] for the extracted feature. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.keysFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.keysFeature */ val > Expect.keys: Expect> get() = _logic.property(Map::keys).transform() @@ -219,7 +219,7 @@ val > Expect.keys: Expect> * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.keys + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.keys */ fun > Expect.keys(assertionCreator: Expect>.() -> Unit): Expect = _logic.property(Map::keys).collectAndAppend(assertionCreator) @@ -231,7 +231,7 @@ fun > Expect.keys(assertionCreator: Expect>.() * * @return The newly created [Expect] for the extracted feature. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.valuesFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.valuesFeature */ val > Expect.values: Expect> get() = _logic.property(Map::values).transform() @@ -244,7 +244,7 @@ val > Expect.values: Expect> * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.values + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.values */ fun > Expect.values(assertionCreator: Expect>.() -> Unit): Expect = _logic.property(Map::values).collectAndAppend(assertionCreator) @@ -258,7 +258,7 @@ fun > Expect.values(assertionCreator: Expect> Expect.asEntries(): Expect>> = _logic.changeSubject.unreported { it.entries } @@ -273,7 +273,7 @@ fun > Expect.asEntries(): Expect> * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapAssertionSamples.asEntries + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapExpectationSamples.asEntries */ fun > Expect.asEntries( assertionCreator: Expect>>.() -> Unit diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapCollectionLikeAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapCollectionLikeAssertions.kt index a06a200b5..ec0607bb3 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapCollectionLikeAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapCollectionLikeAssertions.kt @@ -1,3 +1,4 @@ +//TODO rename file with 0.18.0 to ...Expectations package ch.tutteli.atrium.api.fluent.en_GB import ch.tutteli.atrium.creating.Expect diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryAssertions.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryAssertions.kt index a924b4844..8d115b751 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryAssertions.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryAssertions.kt @@ -18,17 +18,20 @@ import ch.tutteli.atrium.logic.* fun > Expect.isKeyValue(key: K, value: V): Expect = _logicAppend { isKeyValue(key, value) } + +//TODO move to mapEntryExpectations with 0.18.0 /** * Creates an [Expect] for the property [Map.Entry.key] of the subject of `this` expectation, * so that further fluent calls are assertions about it. * * @return The newly created [Expect] for the extracted feature. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapEntryAssertionSamples.keyFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapEntryExpectationSamples.keyFeature */ val > Expect.key: Expect get() = _logic.key().transform() +//TODO move to mapEntryExpectations with 0.18.0 /** * Expects that the property [Map.Entry.key] of the subject of `this` expectation * holds all assertions the given [assertionCreator] creates for it and @@ -36,22 +39,24 @@ val > Expect.key: Expect * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapEntryAssertionSamples.key + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapEntryExpectationSamples.key */ fun > Expect.key(assertionCreator: Expect.() -> Unit): Expect = _logic.key().collectAndAppend(assertionCreator) +//TODO move to mapEntryExpectations with 0.18.0 /** * Creates an [Expect] for the property [Map.Entry.value] of the subject of `this` expectation, * so that further fluent calls are assertions about it. * * @return The newly created [Expect] for the extracted feature. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapEntryAssertionSamples.valueFeature + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapEntryExpectationSamples.valueFeature */ val > Expect.value: Expect get() = _logic.value().transform() +//TODO move to mapEntryExpectations with 0.18.0 /** * Expects that the property [Map.Entry.value] of the subject of `this` expectation * holds all assertions the given [assertionCreator] creates for it and @@ -59,7 +64,7 @@ val > Expect.value: Expect * * @return an [Expect] for the subject of `this` expectation. * - * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.deprecated.MapEntryAssertionSamples.value + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapEntryExpectationSamples.value */ fun > Expect.value(assertionCreator: Expect.() -> Unit): Expect = _logic.value().collectAndAppend(assertionCreator) diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryExpectations.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryExpectations.kt new file mode 100644 index 000000000..60e2deea3 --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapEntryExpectations.kt @@ -0,0 +1,17 @@ +package ch.tutteli.atrium.api.fluent.en_GB + +import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.logic.* + +/** + * Expects that the property [Map.Entry.key] of the subject of `this` expectation + * is equal to the given [key] and the property [Map.Entry.value] is equal to the given [value]. + * + * @return an [Expect] for the subject of `this` expectation. + * + * @sample ch.tutteli.atrium.api.fluent.en_GB.samples.MapEntryExpectationSamples.toEqualKeyValue + * + * @since 0.17.0 + */ +fun > Expect.toEqualKeyValue(key: K, value: V): Expect = + _logicAppend { isKeyValue(key, value) } diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/MapEntryExpectationsSpec.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/MapEntryExpectationsSpec.kt index 71b0fa2a9..fb0aadde5 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/MapEntryExpectationsSpec.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/MapEntryExpectationsSpec.kt @@ -4,8 +4,8 @@ import ch.tutteli.atrium.creating.Expect import ch.tutteli.atrium.specs.* object MapEntryExpectationsSpec : ch.tutteli.atrium.specs.integration.MapEntryExpectationsSpec( - fun2(Expect>::isKeyValue), - fun2(Expect>::isKeyValue).withNullableSuffix(), + fun2(Expect>::toEqualKeyValue), + fun2(Expect>::toEqualKeyValue).withNullableSuffix(), property, String>(Expect>::key), fun1, Expect.() -> Unit>(Expect>::key), property, Int>(Expect>::value), diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapEntryExpectationSamples.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapEntryExpectationSamples.kt new file mode 100644 index 000000000..2797746da --- /dev/null +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/test/kotlin/ch/tutteli/atrium/api/fluent/en_GB/samples/MapEntryExpectationSamples.kt @@ -0,0 +1,73 @@ +package ch.tutteli.atrium.api.fluent.en_GB.samples + +import ch.tutteli.atrium.api.fluent.en_GB.* +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, "a") + + fails { + expect(mapOf(1 to "a").entries.first()).toEqualKeyValue(1, "b") + } + } + + @Test + fun keyFeature() { + expect(mapOf(1 to "a").entries.first()) + .key // subject here is of type Int (actually 1) + .toEqual(1) + + fails { + expect(mapOf(1 to "a").entries.first()) + .key // subject here is of type Int (actually 1) + .toEqual(2) // fails because 1 is not equal to 2 + } + } + + @Test + fun key() { + expect(mapOf(1 to "a").entries.first()) + .key { // subject inside this block is of type Int (actually 1) + toEqual(1) + } + + fails { + expect(mapOf(1 to "a").entries.first()) + .key { // subject inside this block is of type Int (actually 1) + toEqual(2) // fails because 1 is not equal to 2 + } + } + } + + @Test + fun valueFeature() { + expect(mapOf(1 to "a").entries.first()) + .value // subject here is of type String (actually "a") + .toEqual("a") + + fails { + expect(mapOf(1 to "a").entries.first()) + .value // subject here is of type String (actually "a") + .toEqual("b") // fails because "a" is not equal to "b" + } + } + + @Test + fun value() { + expect(mapOf(1 to "a").entries.first()) + .value { // subject inside this block is of type String (actually "a") + toEqual("a") + } + + fails { + expect(mapOf(1 to "a").entries.first()) + .value { // subject inside this block is of type String (actually "a") + toEqual("b") // fails because "a" is not equal to "b" + } + } + } +} diff --git a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/MapEntryExpectationsSpec.kt b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/MapEntryExpectationsSpec.kt index c481b280d..f3fb8e03d 100644 --- a/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/MapEntryExpectationsSpec.kt +++ b/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/MapEntryExpectationsSpec.kt @@ -8,8 +8,8 @@ import org.spekframework.spek2.Spek import org.spekframework.spek2.style.specification.Suite abstract class MapEntryExpectationsSpec( - isKeyValue: Fun2, String, Int>, - isKeyValueNullable: Fun2, String?, Int?>, + toEqualKeyValue: Fun2, String, Int>, + toEqualKeyValueNullable: Fun2, String?, Int?>, keyFeature: Feature0, String>, key: Fun1, Expect.() -> Unit>, valueFeature: Feature0, Int>, @@ -23,12 +23,12 @@ abstract class MapEntryExpectationsSpec( include(object : SubjectLessSpec>( describePrefix, - isKeyValue.forSubjectLess("key", 1) + toEqualKeyValue.forSubjectLess("key", 1) ) {}) include(object : SubjectLessSpec>( "$describePrefix[nullable] ", - isKeyValueNullable.forSubjectLess("key", 1) + toEqualKeyValueNullable.forSubjectLess("key", 1) ) {}) include(object : KeyValueLikeExpectationsSpec, Map.Entry>( @@ -53,18 +53,18 @@ abstract class MapEntryExpectationsSpec( val mapEntry = mapEntry("hello", 1) val fluent = expect(mapEntry) - describeFun(isKeyValue, isKeyValueNullable) { - val isKeyValueFunctions = uncheckedToNonNullable(isKeyValue, isKeyValueNullable) + describeFun(toEqualKeyValue, toEqualKeyValueNullable) { + val toEqualKeyValueFunctions = uncheckedToNonNullable(toEqualKeyValue, toEqualKeyValueNullable) context("map $mapEntry") { - isKeyValueFunctions.forEach { (name, isKeyValueFun) -> + toEqualKeyValueFunctions.forEach { (name, toEqualKeyValueFun) -> it("$name - hello to 1 does not throw") { - fluent.isKeyValueFun("hello", 1) + fluent.toEqualKeyValueFun("hello", 1) } it("$name - hello to 2 throws AssertionError") { expect { - fluent.isKeyValueFun("hello", 2) + fluent.toEqualKeyValueFun("hello", 2) }.toThrow { message { toContain("value: 1", "$toBeDescr: 2") @@ -74,7 +74,7 @@ abstract class MapEntryExpectationsSpec( } it("$name - b to 1 throws AssertionError") { expect { - fluent.isKeyValueFun("b", 1) + fluent.toEqualKeyValueFun("b", 1) }.toThrow { message { toContain("key: \"hello\"", "$toBeDescr: \"b\"") @@ -86,19 +86,19 @@ abstract class MapEntryExpectationsSpec( } } - describeFun(isKeyValueNullable) { - val isKeyValueFun = isKeyValueNullable.lambda + describeFun(toEqualKeyValueNullable) { + val toEqualKeyValueFun = toEqualKeyValueNullable.lambda val mapEntryNullable2 = mapEntry(null as String?, null as Int?) val fluentNullable = expect(mapEntryNullable2) context("map $mapEntryNullable2") { it("null to null does not throw") { - fluentNullable.isKeyValueFun(null, null) + fluentNullable.toEqualKeyValueFun(null, null) } it("null to 2 throws AssertionError") { expect { - fluentNullable.isKeyValueFun(null, 2) + fluentNullable.toEqualKeyValueFun(null, 2) }.toThrow { message { toContain("value: null", "$toBeDescr: 2") @@ -108,7 +108,7 @@ abstract class MapEntryExpectationsSpec( } it("b to null throws AssertionError") { expect { - fluentNullable.isKeyValueFun("b", null) + fluentNullable.toEqualKeyValueFun("b", null) }.toThrow { message { toContain("key: null", "$toBeDescr: \"b\"")