Skip to content

Commit e59d36b

Browse files
authored
Merge pull request #279 from nhaarman/doreturn-overloads
Replace OngoingStubbing<T>.doReturn(List<T>) with doReturnConsecutively.
2 parents ba3294f + 0152304 commit e59d36b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/OngoingStubbing.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.mockito.Mockito
2929
import org.mockito.invocation.InvocationOnMock
3030
import org.mockito.stubbing.Answer
3131
import org.mockito.stubbing.OngoingStubbing
32+
import kotlin.DeprecationLevel.ERROR
3233
import kotlin.reflect.KClass
3334

3435

@@ -63,7 +64,19 @@ fun <T> OngoingStubbing<T>.doReturn(t: T, vararg ts: T): OngoingStubbing<T> {
6364
/**
6465
* Sets consecutive return values to be returned when the method is called.
6566
*/
67+
@Deprecated(
68+
"Use doReturnConsecutively instead",
69+
ReplaceWith("doReturnConsecutively(ts)"),
70+
level = ERROR
71+
)
6672
inline infix fun <reified T> OngoingStubbing<T>.doReturn(ts: List<T>): OngoingStubbing<T> {
73+
return doReturnConsecutively(ts)
74+
}
75+
76+
/**
77+
* Sets consecutive return values to be returned when the method is called.
78+
*/
79+
inline infix fun <reified T> OngoingStubbing<T>.doReturnConsecutively(ts: List<T>): OngoingStubbing<T> {
6780
return thenReturn(
6881
ts[0],
6982
*ts.drop(1).toTypedArray()

tests/src/test/kotlin/test/Classes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ abstract class NonThrowingConstructorWithArgument {
8888
error("Error in constructor")
8989
}
9090

91+
@Suppress("UNUSED_PARAMETER")
9192
constructor(s: String)
9293
}
9394

tests/src/test/kotlin/test/OngoingStubbingTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class OngoingStubbingTest : TestBase() {
255255
fun doReturn_withSingleItemList() {
256256
/* Given */
257257
val mock = mock<Open> {
258-
on { stringResult() } doReturn listOf("a", "b")
258+
on { stringResult() } doReturnConsecutively listOf("a", "b")
259259
}
260260

261261
/* Then */
@@ -330,7 +330,7 @@ class OngoingStubbingTest : TestBase() {
330330
/* When */
331331
try {
332332
mock.stringResult()
333-
} catch(e: UnfinishedStubbingException) {
333+
} catch (e: UnfinishedStubbingException) {
334334
/* Then */
335335
expect(e.message).toContain("Unfinished stubbing detected here:")
336336
expect(e.message).toContain("-> at test.OngoingStubbingTest.testMockitoStackOnUnfinishedStubbing")

0 commit comments

Comments
 (0)