no clue what I'm doing wrong with my mock (mockito...
# announcements
s
no clue what I'm doing wrong with my mock (mockito-kotlin)
Copy code
@Nonnull
    String[] createSfdcObjects(@Nonnull final SObject... sfdcObjects);
mock looks like
whenever(sfdcCrudService.createSfdcObjects(anyVararg()))...
, but it always returns null. I've tried every matcher (
any
,
anyOrNull
, etc) and none of them match. What am I missing?
e
hmm, not sure this is doable. you want something like
Copy code
whenever(sfdcCrudService.createSfdcObjects(*anyVararg())...
but kotlin will copy the vararg array before calling the method...
s
yeah I had tried the spread it didn't work. what do you mean it will copy the array before calling?
e
foo(*bar)
will make a defensive copy of
bar
before passing it to
foo
s
so you think it might not be possible at all to mock this?
e
mockito isn't a great fit for kotlin as it cheats by using nulls all over, which kotlin really wants to check
s
I'm cool to switch in this one spot if you have a recommendation
e
ah, reading up to your original post I see you're using mockito-kotlin, so that does try to work around most of those issues, but still...
s
yeah using mockito-kotlin, but pretty sure we have mockk imported already, so I can use that as well.
don't really care as long as I can solve this. I'm trying to convert an existing java test to kotlin, and it has thousands of assertions and mocks.
it's terrible.
maybe just checking
isA
with something, but not sure what to check.
I don't understand why it won't match
any()