How do you verify the number of elements in a set in Easymock? The class I’m testing should call a method, passing in a set with n elements. Right now, I’m matching any object for the list:
mockFooSetReceiver.saveFooSet(eq(name),
(List<IFooSet>) anyObject());
replay(mockFooSetReceiver);
What I’d like to specify the number of elements in the set:
mockFooSetReceiver.saveFooSet(eq(name),
setOfNObject(100));
replay(mockFooSetReceiver);
Or better yet, match the elements in the set:
mockFooSetReceiver.saveFooSet(eq(name),
setEq(ecpectedSet));
replay(mockFooSetReceiver);
Do I have to roll my own matcher, of is there one built in? Or does someone have a setOfNObject or setEq matcher that they’d like to share?
As Sets must implement equals(..) according to this contract:
a simple EasyMock.eq(ecpectedSet) does the job.
If it’s only the size of the set @Guillaume’s answer is the way to go.