Java – ambiguous mockito – 0 matches expectation, 1 record (invaliduseofmatchersexception)

I face a very strange problem@ H_ 301_ 2@URL = "/my/specific/url/"; when(this.restHelperMock.post( eq(myEnum),eq(this.config.apiEndpoint() + URL),any(JSONObject.class))). thenReturn(new JSONObject(myDesiredJsonContent));

Even include

Give it to me

Even if I don't use raw expressions Strangely, if I change the contains method to:

Omit the endpoint, how it works

Config and resthelper are ridiculed:

The URL of apiendpoint is equal to what I want to simulate. Even if it won't, I should get a NullPointerException because of false mockery But here, I have no idea

Thank you for your answer

Solution

The problem seems to be that you called an analog method this during the EQ (...) call config. apiEndpoint(). Trying to simply put the full URL there (host: port / API / my / specific / url) instead of calling another simulation there may confuse mockito because it relies on the internal state for simulation

To be honest, I'm not so deep into mockito. I can explain why this happens, but one day I may try to debug it; -)

Editor: strangely, I can't seem to reproduce it with simpler test cases There seems to be more here than satisfied eyes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>