Continuing my question from yesterday, I'm still u...
# announcements
s
Continuing my question from yesterday, I'm still unable to mock (using mockito-kotlin) a call to a java service that takes in varargs. It always returns null.
Copy code
private String createObjectsWithRetry(final SObject... objects) {
...
    id = crudService.createObjects(objects)[0];
...
}

whenever(crudService.createObjects(anyVararg())).thenReturn(listOf("a","b").toTypedArray())
whenever(crudService.createObjects(any<SObject>())).thenReturn(listOf("a","b").toTypedArray())
whenever(crudService.createObjects(any())).thenReturn(listOf("a","b").toTypedArray())
whenever(sfdcCrudService.createSfdcObjects(argThat{true})).thenReturn(listOf("a","b").toTypedArray())
...and more
The result is always null. I would expect all of these to work, but they do not. I cannot figure out what is wrong. It appears it has to do with how Java treats the varargs being passed as a param straight to a new method.
m
Why you don't use mockk library?
s
because the project is already using mockito-kotlin and the tests I'm modifying already use mockito. Converting would not be easy, even for a single test.