I have a Foo
class which is SUT and a Bar
class, which is its collaborator. Foo
calls run(List
on the Bar
with "expectedList
" as an argument. Then, Foo
will add a few more elements to this List
so that its state will be different from what it was at the time of calling run()
. Here's my test case.
@Test
public void testFoo() {
Bar collaborator = spy(new Bar());
Foo sut = new Foo(collaborator);
verify(collaborator).run(expectedList);
}
Note that the collaborator is actually a spy object rather than a mock. This test case will fail because even though run()
was called with an argument equal to expectedList
, it was modified since and its current value no longer equals expectedList
. However, this is the way it is supposed to work, so I'm wondering if there's a way to have Mockito store the snapshot of parameters when a method is called and verify them based on these values rather than the most recent values.