Wednesday, October 08, 2008

Custom argument matching with Mockito

I wrote up a wiki entry on my continuing adventures with Mockito.   This time, I'm trying to perform state verification of the inputs to the test double dependency.  And again, Mockito does not disappoint with its awesome Matchers and ArgumentMatcher support.  I'm really enjoying the use of Mockito.  Very much recommended.



  1. I would strongly agree that this is the most intuitive mocking framework. I was pairing with a co-developer today to fix the failed controller test (refactoring effort) written using easymock. It was a null pointer. The refactored service got to be bootstrapped in the controller to fix it. The test should now account for additional expectation (refactored service), replay and verification. It took sometime for the co-developer to understand about what's going on (expect-replay-verify). Mockito's Stub-verify is more intuitive though and additionally its annotations reduce verbosity in the setup.
    Verifying indirect tests using mocked dependency just blew my mind. Awesome.

  2. That's cool -- I've not tried this. But -- shouldn't line 52 return false? If you are not even the correct instance, that id a match failure, yes?

  3. ...never mind -- I get it. It's a matter of coding style.

    I opted to throw IllegalArgumentException if the instance type is unexpected, but you could argue that's overkill.

    Nice post. Thanks.

  4. Wonderfull blog post,keep sharing this.
    contact us
    Bridal Jewellery for Rent in Bangalore