Closed BoD closed 3 years ago
private val otpViewModel = mock
{ on { mustSwitchOtpFromAppToSms() } itAnswers { mustSwitchOtpFromAppToSms } on { createMfaBySms() } itAnswers { createMfaBySmsResponse } on { showError } itAnswers { showErrorLiveData } }
@BoD There's no itAnswers
method in Mockito-kotlin.
Oh you're right, this is from Kluent actually... But still this only happens when updating the version of mockito-kotlin. Do you have an idea of what could be the issue, or should I try to open an issue on the Kluent project? 😊
I would check my imports. I don't know Kluent, but my guess is that on
might be the from Mockito-kotlin, where it probably should have used on
from Kluent?
So I checked and there is no on
in Kluent - but if I use doAnswer
from mockito-kotlin, I still have the same error.
Here's my imports:
import com.nhaarman.mockitokotlin2.doAnswer
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.never
import com.nhaarman.mockitokotlin2.timeout
import com.nhaarman.mockitokotlin2.verify
(other imports omitted but nothing from Kluent anymore)
and the modified version:
private val otpViewModel = mock<OTPSetupViewModel> {
on { mustSwitchOtpFromAppToSms() } doAnswer { mustSwitchOtpFromAppToSms }
on { createMfaBySms() } doAnswer { createMfaBySmsResponse }
on { showError } doAnswer { showErrorLiveData }
}
Any idea what could be wrong?
Oh I have more info: I also upgraded org.mockito:mockito-core
from 3.0.0 to 3.1.0. If I revert to 3.0.0 I no longer have this issue. That makes sense?
Oh I have more info: I also upgraded org.mockito:mockito-core from 3.0.0 to 3.1.0. If I revert to 3.0.0 I no longer have this issue. That makes sense?
Makes sense, as Mockito-kotlin internally relies on Mockito. There's probably a breaking change in Mockito.
All right thank you. I just looked and I notice Mockito-kotlin depends on a fairly old version of org.mockito:mockito-core
(2.23.0
). I guess it would be cool to upgrade that. In the meantime I think on my side I'll stay with mockito-kotlin 2.1.0
.
Thanks!
So if I understand correctly mockito-kotlin 2.2.0
works fine with Mockito 3.0.0
but not with Mockito 3.1.0
, correct?
That's correct.
@BoD Could you post a bit more of the test code? Can't reproduce the issue with upgraded mockito-core dependency.
I had the same issue and we also use Kluent. In this Test it turned out we used the mock method from Kluent instead of mockitotokotlin and with that we got:
java.lang.NoSuchMethodError: com.nhaarman.mockitokotlin2.MockingKt.withSettings([Lkotlin/reflect/KClass;Ljava/lang/String;Ljava/lang/Object;Lorg/mockito/stubbing/Answer;ZLorg/mockito/mock/SerializableMode;Z[Lorg/mockito/listeners/InvocationListener;ZLcom/nhaarman/mockitokotlin2/UseConstructor;Ljava/lang/Object;)Lorg/mockito/MockSettings;
After changing from import org.amshove.kluent.mock to
import com.nhaarman.mockitokotlin2.mock
the test works fine.
Sorry to reply so late. I can confirm that we do use the mock
method from mockitokotlin and have the issue so that's not the culprit.
If a new version of mockito-kotlin with an up-to-date version of the dependency to mockito could be released, I can easily see if that resolves the issue. Plus I guess it's generally a good idea to be up to date ;)
It's been several years :) Would it be possible to try to make mockito-kotlin depend on a recent version of mockito?
Currently it depends on 2.23.0
from Oct 2018, while the latest is 3.8.0
from Feb 2021.
See #408 as well for updated dependencies.
I've been trying to upgrade from
2.1.0
to2.2.0
and now I have a few tests that fail with this exception:This is on a test that does something like this:
Any idea?