https://kotlinlang.org logo
#announcements
Title
# announcements
b

billybong

05/08/2017, 11:49 AM
example
Copy code
val rights: MyApiClient = mock<MyApiClient>{
        on {fetchByIds(any())} doReturn emptyList<Response>()
    }
n

nhaarman

05/08/2017, 11:52 AM
billybong: What is the definition of
MyApiClient
and
fetchById
, and what is the stack trace?
b

billybong

05/08/2017, 11:58 AM
MyApiClient is an open class (spring bean) and fetchId receives a list of id’s based on a domain class
n

nhaarman

05/08/2017, 12:04 PM
it could be that the body of
fetchByIds
is still executed because it can't be mocked: is it declared
open
as well?
b

billybong

05/08/2017, 12:04 PM
aah, you mean the function as well?
n

nhaarman

05/08/2017, 12:04 PM
exactly
b

billybong

05/08/2017, 12:04 PM
Is there anyway around that?
t

tapchicoma

05/08/2017, 12:05 PM
mockito 2 can mock final methods as well
can you show
fetchByIds()
function definition? It may happen that it returns list of
Response?
type
n

nhaarman

05/08/2017, 12:09 PM
the only way around not adding
open
to the function is to use `mock-maker-inline`: https://github.com/mockito/mockito/wiki/What's-new-in-Mockito-2#unmockable
b

billybong

05/08/2017, 12:10 PM
no it doesn’t. nhaarman was right that the method was not open and I was using Mockito 1.9. That lead me to the correct answer
Yup, the same as Hadi blogged about above. Big thanks for the help
👍 1