Skip to content
Advertisement

jersey/Mockito: NullInsteadOfMockException on client.post call verification

I’ve run into a strange issue with unit testing the following jersey client call:

JavaScript

PostBody is a MultivaluedMap.

The unit test verifies fine the accept and type calls but fails on the post one with this exception:

JavaScript

Here’s the test code:

JavaScript

Can you see anything wrong with this code?

Advertisement

Answer

Yes. You’ve misused verify. The argument to verify has to be the mock itself. Then you call the method you want to verify on the value that’s returned by verify. So in this case, the first verify call should be

JavaScript

and similarly for the other verify calls.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement