I am writing a BDD test with Cucumber and mockito_kotlin. The verify function is like:
@Then("there shouldn't be any coockie eaten.")
fun there_shouldnt_be_any_coockie_eaten() {
verify(mockCoockie, never()).eatGoodCookie()(any(), any())
}
ICookie interface:
interface ICookie {
val cookieSauce: Sauce?
fun eatGoodCookie(): ListenableFuture<GetCookieListResult>
fun eatBadCookie(): ListenableFuture<GetCookieListResult>
//...
}
My mockCookie in test class:
private val mockCookie = mock<ICookie> {
on { cookieSauce }.thenReturn(mock()) ------- Line 35
on { eatGoodCookie(any(), any()) }
.thenReturn(Futures.immediateFuture(GetCookieListResult().apply {
appList = emptyArray()
})).thenReturn(Futures.immediateFuture(GetCookieListResult().apply {
appList = arrayOf(theOnlyCookieCatalog)
}))
//...
}
But I encountered these error:
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: -> at com.nhaarman.mockito_kotlin.MockitoKt.whenever(Mockito.kt:253)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, which is not supported
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
I do not know I against which tule. Did someone encounter similar problem?
The version of related tools are:
testImplementation 'org.mockito:mockito-core:3.2.4'
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
testImplementation 'org.hamcrest:hamcrest-library:1.3'