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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: