/
ExposeTest.kt
40 lines (33 loc) · 1.17 KB
/
ExposeTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.sksamuel.kotlintest
import io.kotlintest.assertions.extracting
import io.kotlintest.matchers.collections.shouldContainAll
import io.kotlintest.shouldBe
import io.kotlintest.shouldThrowAny
import io.kotlintest.specs.WordSpec
class ExposeTest : WordSpec() {
init {
data class Person(val name: String, val age: Int, val friends: List<Person>)
val p1 = Person("John Doe", 20, emptyList())
val p2 = Person("Samantha Rose", 19, listOf(p1))
val persons = listOf(p1, p2)
"extracting" should {
"extract simple properties"{
extracting(persons) { name }
.shouldContainAll("John Doe", "Samantha Rose")
}
"extract complex properties"{
extracting(persons) { Pair(name, age) }
.shouldContainAll(
Pair("John Doe", 20),
Pair("Samantha Rose", 19)
)
}
"fail if the matcher fails"{
shouldThrowAny {
extracting(persons) { name }
.shouldContainAll("<Some name that is wrong>")
}.message shouldBe "Collection should contain all of \"<Some name that is wrong>\" but missing \"<Some name that is wrong>\""
}
}
}
}