alexcuesta

My tech blog

Verifying argument values with Mockito

leave a comment »

Sometimes it is necessary to verify that a mock object is called with the right argument.

We can do this with org.mockito.ArgumentCaptor like this:

ArgumentCaptor<SteeringWheel> wheelArgument = ArgumentCaptor.forClass(SteeringWheel.class);
verify(carMock).turn(wheelArgument.capture());
assertEquals(Direction.LEFT, wheelArgument.getDirection();

Written by alexcuesta

February 17, 2010 at 4:04 pm

Posted in Java

Leave a comment