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
Original issue reported on code.google.com by
everf...@gmail.com
on 13 Jun 2010 at 12:04