-
Notifications
You must be signed in to change notification settings - Fork 4
/
AppUseCaseShould.kt
80 lines (71 loc) 路 2.28 KB
/
AppUseCaseShould.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.rogervinas.wiremock
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(MockKExtension::class)
class AppUseCaseShould {
private val name = "Tim"
private val fooResponse = "Hi I am Foo"
private val fooError = "Sorry Foo failed"
private val barResponse = "Hi I am Bar"
private val barError = "Sorry Bar failed"
@MockK
lateinit var fooClient: FooClient
@MockK
lateinit var barClient: BarClient
@Test
fun `call foo and bar`() {
every { fooClient.call(name) } returns fooResponse
every { barClient.call(name) } returns barResponse
assertThat(AppUseCase().execute(name, fooClient, barClient)).isEqualTo(
"""
Hi! I am $name
I called Foo and its response is $fooResponse
I called Bar and its response is $barResponse
Bye!
""".trimIndent()
)
}
@Test
fun `call foo and bar even if foo fails`() {
every { fooClient.call(name) } throws Exception(fooError)
every { barClient.call(name) } returns barResponse
assertThat(AppUseCase().execute(name, fooClient, barClient)).isEqualTo(
"""
Hi! I am $name
I called Foo and it failed with $fooError
I called Bar and its response is $barResponse
Bye!
""".trimIndent()
)
}
@Test
fun `call foo and bar even if bar fails`() {
every { fooClient.call(name) } returns fooResponse
every { barClient.call(name) } throws Exception(barError)
assertThat(AppUseCase().execute(name, fooClient, barClient)).isEqualTo(
"""
Hi! I am $name
I called Foo and its response is $fooResponse
I called Bar and it failed with $barError
Bye!
""".trimIndent()
)
}
@Test
fun `call foo and bar even if both fail`() {
every { fooClient.call(name) } throws Exception(fooError)
every { barClient.call(name) } throws Exception(barError)
assertThat(AppUseCase().execute(name, fooClient, barClient)).isEqualTo(
"""
Hi! I am $name
I called Foo and it failed with $fooError
I called Bar and it failed with $barError
Bye!
""".trimIndent()
)
}
}