link to sample of isKeyValue and other cleanup

This commit is contained in:
Robert Stoll
2021-05-31 12:15:23 +02:00
parent 37b8749566
commit b913776218
3 changed files with 28 additions and 79 deletions

View File

@@ -12,6 +12,8 @@ import ch.tutteli.atrium.logic.*
* reporting etc.
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.deprecated.MapEntryAssertionSamples.isKeyValue
*/
@Deprecated("Use toEqualKeyValue; will be removed with 1.0.0 at the latest", ReplaceWith("this.toEqualKeyValue<K, V, T>(keyValuePair)"))
infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.isKeyValue(keyValuePair: Pair<K, V>): Expect<T> =
@@ -22,9 +24,9 @@ infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.isKeyValue(keyValuePair: Pair<K,
* Creates an [Expect] for the property [Map.Entry.key] 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.keyFeature
*
* @return The newly created [Expect] for the extracted feature.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.keyFeature
*/
val <K, T : Map.Entry<K, *>> Expect<T>.key: Expect<K>
get() = _logic.key().transform()
@@ -35,9 +37,9 @@ val <K, T : Map.Entry<K, *>> Expect<T>.key: Expect<K>
* 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.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.key
*/
infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.key(assertionCreator: Expect<K>.() -> Unit): Expect<T> =
_logic.key().collectAndAppend(assertionCreator)
@@ -47,9 +49,9 @@ infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.key(assertionCreator: Expect<K>.
* 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.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.valueFeature
*/
val <V, T : Map.Entry<*, V>> Expect<T>.value: Expect<V>
get() = _logic.value().transform()
@@ -60,9 +62,9 @@ val <V, T : Map.Entry<*, V>> Expect<T>.value: Expect<V>
* 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.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.MapEntryExpectationSamples.value
*/
infix fun <K, V, T : Map.Entry<K, V>> Expect<T>.value(assertionCreator: Expect<V>.() -> Unit): Expect<T> =
_logic.value().collectAndAppend(assertionCreator)

View File

@@ -12,44 +12,32 @@ class MapEntryExpectationSamples {
@Test
fun toEqualKeyValue() {
expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "a")
// | | | subject here is type of Map.Entry<Int, String> (actually (1 to "a"))
// | | subject here is type of Set<Map.Entry<Int, String>>
// | subject here is type of Map<Int, String>
fails {
// fails because (1 to "a") is not equal to (1 to "b")
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<Int, String> (actually (1 to "a"))
// | | subject here is type of Set<Map.Entry<Int, String>>
// | subject here is type of Map<Int, String>
}
}
@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<Int, String>
// | | subject here is type of Int (actually 1)
// | subject here is of type Map.Entry<Int, String>
fails {
// fails because 1 is not equal to 2
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<Int, String>
// | | subject here is type of Int (actually 1)
// | subject here is of type Map.Entry<Int, String>
}
}
@Test
fun key() {
// | subject here is of type Map<Int, String>
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<Int, String>
fails { // because 1 is not equal to 2
expect(mapOf(1 to "a").entries.first()).key { // subject inside this block is of type Int (actually 1)
this toEqual 2
}
@@ -59,29 +47,23 @@ class MapEntryExpectationSamples {
@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<Int, String>
// | | subject here is of type String (actually "a")
// | subject here is of type Map.Entry<Int, String>
fails {
// fails because "a" is not equal to "b"
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<Int, String>
// | | subject here is of type String (actually "a")
// | subject here is of type Map.Entry<Int, String>
}
}
@Test
fun value() {
// | subject here is of type Map<Int, String>
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<Int, String>
fails { // because "a" is not equal to "b"
expect(mapOf(1 to "a").entries.first()) value { // subject inside this block is of type String (actually "a")
this toEqual "b"
}

View File

@@ -1,3 +1,6 @@
//TODO remove file with 1.0.0
@file:Suppress("DEPRECATION")
package ch.tutteli.atrium.api.infix.en_GB.samples.deprecated
import ch.tutteli.atrium.api.infix.en_GB.*
@@ -9,48 +12,10 @@ class MapEntryAssertionSamples {
@Test
fun isKeyValue() {
expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "a")
expect(mapOf(1 to "a").entries.first()) isKeyValue (1 to "a")
fails {
expect(mapOf(1 to "a").entries.first()) toEqualKeyValue (1 to "b")
expect(mapOf(1 to "a").entries.first()) isKeyValue (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" }
}
}
}