Search code examples
javajmockit

Check "any" param in JMockit NonStrictExpectations


I have this NonStrictExpectations:

new NonStrictExpectations(){
  {
    mDogDao.saveAllDog((Collection<Dog>) any);
    // do some validation on **any**
    times = 1;
  }
};

How can I do some assertions on the any parameter? I know that is definitely possible... but I do not know what I have to look for.

Thanks for your support.

Stefan


Solution

  • Try using Verifications instead of Expectations:

    new Verifications() {{
        Collection<Dog> dogCollection;
    
        mDogDao.saveAllDog(dogCollection = withCapture());
    
        assertEquals(5, dogCollection.size());
    }};
    

    Have a look at the withCapture() documentation for more information.