How can I solve this. I was reading about hamcrest but can't see the
light (yet).
Any pointer to a code example would be helpful.
This the argument I'm talking about:
http://code.google.com/intl/nl/appengine/docs/java/javadoc/com/google/appengine/api/urlfetch/HTTPRequest.html
when(urlFetchService.fetch(httpRequest).thenReturn(httpResponse);
Cheers,
Marcel
package com.footdex.test.appengine.api.urlfetch;
import static org.mockito.Matchers.argThat;
import java.net.URL;
import org.mockito.ArgumentMatcher;
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
public class HTTPRequestMatcher extends ArgumentMatcher<HTTPRequest> {
URL url;
HTTPMethod method;
public HTTPRequestMatcher(URL url, HTTPMethod method) {
this.url = url;
this.method = method;
}
@Override
public boolean matches(Object argument) {
HTTPRequest request = (HTTPRequest)argument;
return request.getURL().equals(url) && request.getMethod
().equals(method);
}
public static HTTPRequest matchesRequest(URL url, HTTPMethod
method) {
return argThat(new HTTPRequestMatcher(url, method));
}
}
For stubbing purposes: If equals() arg matching don't work you can:
- implement a matcher (as you did)
- relax the stubbing and use 'any()' argument matcher
For verification you can also use ArgumentCaptor to capture args for
future verifications.
Hope that helps!
Cheers,
Szczepan Faber
> --
> You received this message because you are subscribed to the Google Groups "mockito" group.
> To post to this group, send email to moc...@googlegroups.com.
> To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mockito?hl=en.
>
>
>
>
As you have seen above I already implemented the custom matcher.
I needed this as I wanted to test that some specific argument values
were passed to my mock, so any() was not sufficient.
Cheers,
Marcel