Skip to content

Commit 3566e91

Browse files
committed
Merge branch 'dpreussler-inorder' into 1.x
2 parents 916f186 + 94f17fa commit 3566e91

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ fun ignoreStubs(vararg mocks: Any): Array<out Any> = Mockito.ignoreStubs(*mocks)
116116
fun inOrder(vararg mocks: Any): InOrder = Mockito.inOrder(*mocks)!!
117117
fun inOrder(vararg mocks: Any, evaluation: InOrder.() -> Unit) = Mockito.inOrder(*mocks).evaluation()
118118

119+
inline fun <T> T.inOrder(block: InOrderOnType<T>.() -> Any) {
120+
block.invoke(InOrderOnType(this))
121+
}
122+
123+
class InOrderOnType<T>(private val t: T) : InOrder by inOrder(t as Any) {
124+
fun verify() : T = verify(t)
125+
}
126+
119127
inline fun <reified T : Any> isA(): T = Mockito.isA(T::class.java) ?: createInstance<T>()
120128
fun <T : Any> isNotNull(): T? = Mockito.isNotNull()
121129
fun <T : Any> isNull(): T? = Mockito.isNull()

mockito-kotlin/src/test/kotlin/test/MockitoTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ class MockitoTest : TestBase() {
225225
}
226226
}
227227

228+
@Test
229+
fun testInOrderWithReceiver() {
230+
/* Given */
231+
val mock = mock<Methods>()
232+
233+
/* When */
234+
mock.string("")
235+
mock.int(0)
236+
237+
/* Then */
238+
mock.inOrder {
239+
verify().string(any())
240+
verify().int(any())
241+
verifyNoMoreInteractions()
242+
}
243+
}
244+
228245
@Test
229246
fun testClearInvocations() {
230247
val mock = mock<Methods>().apply {

0 commit comments

Comments
 (0)