-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuzzPresenterImplTest.kt
100 lines (75 loc) · 3.04 KB
/
BuzzPresenterImplTest.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package co.zsmb.example.cleanbuzz.presentation
import android.content.Context
import co.zsmb.example.cleanbuzz.R
import co.zsmb.example.cleanbuzz.domain.BuzzResult
import co.zsmb.example.cleanbuzz.domain.usecase.BuzzUseCase
import co.zsmb.example.cleanbuzz.presentation.buzz.BuzzPresenterImpl
import co.zsmb.example.cleanbuzz.presentation.buzz.BuzzView
import co.zsmb.example.cleanbuzz.presentation.buzz.PresentableResult
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockito_kotlin.whenever
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class BuzzPresenterImplTest {
companion object {
private val ERROR_NUMBER_INFO = "ERROR_NUMBER_INFO"
}
@Mock lateinit var context: Context
@Mock lateinit var view: BuzzView
@Mock lateinit var usecase: BuzzUseCase
lateinit var buzzPresenter: BuzzPresenterImpl
@Before
fun setUp() {
whenever(context.getString(R.string.error_number_info)) doReturn ERROR_NUMBER_INFO
buzzPresenter = BuzzPresenterImpl(
context = context,
buzzUseCase = usecase,
mainScheduler = Schedulers.trampoline())
buzzPresenter.bind(view)
}
@Test
fun requestNumberWithEmptyString_showsErrorInView() {
buzzPresenter.requestNumber("")
verify(view).showResult(PresentableResult(result = ERROR_NUMBER_INFO, isError = true))
}
@Test
fun requestNumberWithMinValue_showsResultInView() {
whenever(usecase.execute(any())) doReturn Single.just(BuzzResult("1"))
buzzPresenter.requestNumber("1")
verify(view).showResult(PresentableResult(result = "1", isError = false))
}
@Test
fun requestNumberWithMaxValue_showsResultInView() {
whenever(usecase.execute(any())) doReturn Single.just(BuzzResult("999"))
buzzPresenter.requestNumber("999")
verify(view).showResult(PresentableResult(result = "999"))
}
@Test
fun requestNumberWithJustBelowMinValue_showsErrorInView() {
buzzPresenter.requestNumber("0")
verify(view).showResult(PresentableResult(result = ERROR_NUMBER_INFO, isError = true))
}
@Test
fun requestNumberWithJustAboveMaxValue_showsErrorInView() {
buzzPresenter.requestNumber("1000")
verify(view).showResult(PresentableResult(result = ERROR_NUMBER_INFO, isError = true))
}
@Test
fun requestNumberWithNonNumberArgument_showsErrorInView() {
buzzPresenter.requestNumber("bunny")
verify(view).showResult(PresentableResult(result = ERROR_NUMBER_INFO, isError = true))
}
@Test
fun requestNumberWithInvalidValue_showsErrorInView() {
buzzPresenter.requestNumber("1234")
verify(view).showResult(PresentableResult(result = ERROR_NUMBER_INFO, isError = true))
}
}