I have this code in kotlin: ``` Mockito.`when`(cc...
# spring
d
I have this code in kotlin:
Copy code
Mockito.`when`(ccmService.getApplication(Mockito.eq(appName), Mockito.eq(finodsGroup)))
                .thenReturn(Optional.of(Application(
                        0L,
                        appName,
                        "",
                        email, null, "jfr", "EOS", email, employee, employee, employee, employee)))
but I get
Copy code
-> at com.evry.fs.arch.icpautomate.automator.AutomatorServiceTest.testCreateNamespace(AutomatorServiceTest.kt:39)

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

This message may appear after an NullPointerException if the last matcher is returning an object 
like any() but the stubbed method signature expect a primitive argument, in this case,
use primitive alternatives.
    when(mock.get(any())); // bad use, will raise NPE
    when(mock.get(anyInt())); // correct usage use
the mock is injected with:
Copy code
@MockBean(name = "ccmServiceImpl")
    lateinit var ccmService: CcmService
OK, using https://github.com/nhaarman/mockito-kotlin for the matchers fixed it!
m
don’t want to blame a ‘holly war’ but take a look onto mockk when u will have a minute - I`ve it tried for few simple mocks(in SB2 app) and with
reified
functions it looks very powerful
p
#mockk