only classes are allowed on the left hand side of a class literal when using Mockito and kotlin

Viewed 6613

I used Android studio's conversion tool to convert existing java test class.

I am getting this error :

only classes are allowed on the left hand side of a class literal

Here is the test case used :

Java

doAnswer(answerVoid(
            (OnDataListListener<List<BEntity>> myCallback) -> myCallback.onSuccess(mList))).when(
            mInteractor).performGetBList(any(OnDataListListener.class), anyBoolean());

Kotlin

doAnswer(answerVoid { listener: OnDataListListener<List<BEntity>> ->
      listener.onSuccess(
          emptyList())
    }).`when`<DragonInteractor>(mInteractor)
        .performGetBList(any<OnDataListListener>(OnDataListListener<*>::class.java),
            anyBoolean())

So how to use generic params in this case? Thanks.

2 Answers

first remove OnDataListListener<*>::class.java parameter then add the List<BEntity> in OnDataListListener parameter types

the result is

doAnswer(answerVoid { listener: OnDataListListener<List<BEntity>> ->
  listener.onSuccess(
      emptyList())
}).`when`<DragonInteractor>(mInteractor)
    .performGetBList(any<OnDataListListener<List<BEntity>>>(),
        anyBoolean())
Related