java - Stubbing a method that takes Class as parameter with Mockito -


The problem is a simple method that takes as Class parameter and it irritating me with Mokito I method the Looks like:

  public & lt; You Enum & lt; U & gt; & Amp; Error, T ServiceResponse extended & lt; U & gt; & Gt; T valid (object target, validator verifier, class  response class, class  U & gt; errorNyan);   

It is at least dangerous to God for me ... I could imagine living without it, but the rest of the code base used it with joy ... < / P>

I was going into my unit test, was stopping this method to return a new empty object. But how can I do this with mokitias? I tried:

  When (serviceValidatorStub.validate (none), ISA (UserCommentRequestValidator.class), UserCommentResponse.class, UserCommentError.class) .thenReturn (new UserCommentResponse ());   

But when I'm in Milan Milankrtaon and would introduce the raw values, I get an invalid use of "org.mockito.exceptions.misusing.InvalidUseOfMatchers exception argument matchers!" The problem is, you can not mix logic matchers and real arguments in a macho call.

Therefore, rather do:

  When (serviceValidatorStub.validate (none), ISA (UserCommentRequestValidator.class), eq (UserCommentResponse.class), eq (UserCommentError.class))). (New User Compression Response ());   

To match equality, see the use of eq () logic matcher.

See:

In addition, you class type - == Similar to the Java operator, you can use the similar () logic matcher to match the same identity.

Comments