ssacher-tgm / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

verify only() does not capture arguments #197

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I want to check that a method is the only method called on a mock and capture 
the arguments passed at the same time.
This does not seem to work as expected.

works as expectd:
//mock(emailService
ArgumentCaptor<Map> model = ArgumentCaptor.forClass(Map.class);
verify(emailService).sendEmail(eq(user.getEmailAddress()), 
eq("verificationEmail.ftl"), eq("Email Verification"), model.capture());
assertThat( (User) model.getValue().get("user"), is(user));

does not work, :
ArgumentCaptor<Map> model = ArgumentCaptor.forClass(Map.class);
verify(emailService, only()).sendEmail(eq(user.getEmailAddress()), 
eq("verificationEmail.ftl"), eq("Email Verification"), model.capture());
assertThat( (User) model.getValue().get("user"), is(user));

throws Exception: "org.mockito.exceptions.base.MockitoException: 
No argument value was captured!"

I can add a double verify to make it work like this, but this looks like code 
smell:

ArgumentCaptor<Map> model = ArgumentCaptor.forClass(Map.class);
verify(emailService).sendEmail(eq(user.getEmailAddress()), 
eq("verificationEmail.ftl"), eq("Email Verification"), model.capture());
assertThat( (User) model.getValue().get("user"), is(user));
verify(emailService, only()).sendEmail(eq(initUser.getEmailAddress()), 
eq("verificationEmail.ftl"), eq("Email Verification"), anyMap());

Original issue reported on code.google.com by everf...@gmail.com on 13 Jun 2010 at 12:04

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r2016.

Original comment by szcze...@gmail.com on 14 Jun 2010 at 9:02

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 3 Jul 2011 at 12:43