-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectMockingMockito.kt
52 lines (43 loc) · 1.22 KB
/
ObjectMockingMockito.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
package dev.vadzimv.slowtests
import org.junit.Assert.assertEquals
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class ObjectMockingMockito {
@Test
fun `a - two plus two`() {
val plus = createMockPlus()
assertEquals(4, plus.doPlus(2, 2))
}
@Test
fun `b - two plus two copy`() {
val plus = createMockPlus()
assertEquals(4, plus.doPlus(2, 2))
}
@Test
fun `c - two plus two copy with verify`() {
val plus = createMockPlus()
assertEquals(4, plus.doPlus(2, 2))
verify(plus) { plus.doPlus(2,2) }
}
@Test
fun `d - two minus two`() {
val minus = createMockMinus()
assertEquals(0, minus.doMinus(2, 2))
}
@Test
fun `e - two minus two copy 1`() {
val minus = createMockMinus()
assertEquals(0, minus.doMinus(2, 2))
}
private fun createMockPlus() = mock<Plus> {
on { doPlus(2, 2) } doReturn 4
}
private fun createMockMinus() = mock<Minus> {
on { doMinus(2, 2) } doReturn 0
}
}