Closed GoogleCodeExporter closed 9 years ago
Thanks for detailed report, I'll take a look at it.
Original comment by iczechowski@gmail.com
on 13 Mar 2008 at 10:33
Original comment by szcze...@gmail.com
on 16 Mar 2008 at 2:50
Again, thank you very much for very detailed report and for suggesting the fix.
InvocationMatcher.isSimilarTo() method have no effect on verification. This
method is
only used to decide what kind of verification message to print. E.g. at the
point
when isSimilarTo() is called the verification has already failed.
I created a test case according to your description and everything works fine
(can
you paste it to your IDE and tell me if this is it?):
{{{
interface View {
void addProperty(String property);
void addProperty(DomainObject property);
}
class DomainObject {}
class CustomDomainMatcher extends ArgumentMatcher<DomainObject> {
@Override public boolean matches(Object argument) {
return true;
}
}
@Test
public void testBug() throws Exception {
View view = mock(View.class);
view.addProperty(new DomainObject());
view.addProperty("test");
verify(view, atLeastOnce()).addProperty(argThat(new CustomDomainMatcher()));
verify(view, times(1)).addProperty(argThat(new CustomDomainMatcher()));
verify(view, atLeastOnce()).addProperty("test");
verify(view, times(1)).addProperty("test");
}
}}}
Misbehaviour in your code may be related to following:
Look at this line:
verify(view, atLeastOnce()).addProperty( argThat(new CustomDomainMatcher()) );
Given that addProperty() method is overloaded in your code, it is very
important what
kind of generic type your customDomainMatcher is defined with:
class CustomDomainMatcher extends ArgumentMatcher<DomainObject> {
or
class CustomDomainMatcher extends ArgumentMatcher<String> {
Compiler uses this generic type to determine which overloaded version of the
method
to use.
If your matcher is not generic, you have to cast the argument to make compiler
happy:
verify(view, atLeastOnce()).addProperty((DomainObject) argThat(new
customDomainMatcher()) );
Closing the bug - please reopen if it still doesn't work for you.
Original comment by szcze...@gmail.com
on 16 Mar 2008 at 3:09
It will be a few days, but I will give that a try in my environment.
K
Original comment by kevin.da...@gmail.com
on 24 Mar 2008 at 9:02
Original comment by szcze...@gmail.com
on 19 Apr 2009 at 7:40
Original issue reported on code.google.com by
kevin.da...@gmail.com
on 13 Mar 2008 at 6:02Attachments: