Skip to content

Commit

Permalink
Map entry mapping function
Browse files Browse the repository at this point in the history
Fixes #45
  • Loading branch information
robfletcher committed Jun 5, 2018
1 parent 23b2367 commit 7e77f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion strikt-core/src/main/kotlin/strikt/assertions/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package strikt.assertions
import strikt.api.Assertion

fun <T : Map<K, V>, K, V> Assertion<T>.isEmpty() =
passesIf("is empty") { isEmpty() }
passesIf("is empty") { isEmpty() }

operator fun <T : Map<K, V>, K, V> Assertion<T>.get(key: K): Assertion<V?> =
map("entry [$key] %s") { get(key) }
10 changes: 10 additions & 0 deletions strikt-core/src/test/kotlin/strikt/Mapping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import strikt.assertions.containsExactly
import strikt.assertions.first
import strikt.assertions.get
import strikt.assertions.isEqualTo
import strikt.assertions.isNotNull
import strikt.assertions.isNull
import strikt.assertions.last
import java.time.LocalDate

Expand Down Expand Up @@ -37,6 +39,14 @@ internal object Mapping : Spek({
expect(subject)[1..2].containsExactly("rubberplant", "marzipan")
}
}

describe("mapping assertions on ${Map::class.java.simpleName}") {
it("maps to a value element using [key]") {
val subject = mapOf("foo" to "bar")
expect(subject)["foo"].isNotNull().isEqualTo("bar")
expect(subject)["bar"].isNull()
}
}
}

describe("custom mapping") {
Expand Down

0 comments on commit 7e77f65

Please sign in to comment.