https://kotlinlang.org logo
Title
r

Ruckus

05/09/2018, 3:33 PM
I don't have any experience with mockito, but you can try asking in #mocking
z

ziggy42

05/09/2018, 3:33 PM
I saw the channel but it's not active 😕
r

Ruckus

05/09/2018, 3:34 PM
Yeah, that's the sad reality of this slack. Lots of channels are more or less abandoned. Did you try #test?
z

ziggy42

05/09/2018, 3:34 PM
I'll try now, thanks!
👍 1
n

neil.armstrong

05/09/2018, 3:46 PM
did you call
MockitoAnnotations.initMocks(this)
? You need to do that for the
@Mock
annotation to work
z

ziggy42

05/09/2018, 3:47 PM
Nope 😄
But it works for everything else
n

neil.armstrong

05/09/2018, 3:47 PM
I usually prefer just
mock<Type>()
🙂
z

ziggy42

05/09/2018, 3:48 PM
Yes, I'm using this library, but why do I need to do it? I have tens of tests without calling initMocks
n

neil.armstrong

05/09/2018, 3:49 PM
it isn’t
open
mockito can only mock
open
functions and properties
z

ziggy42

05/09/2018, 3:49 PM
I'm using
kotlin-spring
plugin
n

neil.armstrong

05/09/2018, 3:49 PM
by default everything in kotlin is
final
and mockito cannot mock them (unless you configure it)
at least, I think that might be the issue 😮
z

ziggy42

05/09/2018, 3:50 PM
It could be, but
kotlin-spring
makes everything open 😕
Also this test was passing before I converted the instance to extend an abstract class
n

neil.armstrong

05/09/2018, 3:50 PM
hmm, I’ve never used kotlin-spring so didn’t know that
maybe
kotlin-spring
doesn’t do that for abstract classes?
try making it open and see what happens
though abstract should be open by default I would imagine, or else how do you override 😄
z

ziggy42

05/09/2018, 3:54 PM
with open it works -.-
thanks!
n

neil.armstrong

05/09/2018, 3:56 PM
¯\_(ツ)_/¯
z

ziggy42

05/09/2018, 3:56 PM
But it's super ugly this way...
n

neil.armstrong

05/09/2018, 3:57 PM
Maybe have a google around abstract with the
kotlin-spring
plugin, might be a known issue with workarounds
j

jk

05/09/2018, 5:11 PM
doesn’t kotlin-spring just open the Spring-annotated classes, like @Component etc. ? you can add mockito-inline to your test dependencies to allow you to mock final classes