I test this code:
PublisherCallbackWithLog publisherCallback = new PublisherCallbackWithLog<String>();
for (SdkRequest.SdkRequest sdkRequest : SdkRequestsList.getRequestList()) {
final String s = TextFormat.printToUnicodeString(sdkRequest);
customPublisher.publish(s, publisherCallback);
}
in my test I have this line:
verify(customPublisher, times(1)).publish(argThat(eqWithoutRequestId(sdkRequest)), any(PublisherCallbackWithLog.class));
but I get an error, seems about the 2nd argument.
Argument(s) are different! Wanted:
customPublisher.publish(
,
<any>
);
-> at com.w.sdkService.servlets.SdkPollerServlet_PublishTest.readFromSpreadsheet3Rows_shouldPublish2Times(SdkPollerServlet_PublishTest.java:75)
Actual invocation has different arguments:
customPublisher.publish(
"partner {
display_name: "WTest"
android_pkg_name: "com.example.eliran.myapplication"
sharing_mode: DATA
}
requestId: "3a7458b6-edc0-4d4e-b52e-d2a3847bef0b"
requestType: REMOVE
",
com.w.sdkService.services.callback.PublisherCallbackWithLog@56f6d40b
);
-> at com.w.sdkService.servlets.SdkPollerServlet.publishAddPartnersRequests(SdkPollerServlet.java:101)
Comparison Failure: <Click to see difference>
Argument(s) are different! Wanted:
customPublisher.publish(
,
<any>
);
-> at com.w.sdkService.servlets.SdkPollerServlet_PublishTest.readFromSpreadsheet3Rows_shouldPublish2Times(SdkPollerServlet_PublishTest.java:75)
Actual invocation has different arguments:
customPublisher.publish(
"partner {
display_name: "WTest"
android_pkg_name: "com.example.eliran.myapplication"
sharing_mode: DATA
}
requestId: "3a7458b6-edc0-4d4e-b52e-d2a3847bef0b"
requestType: REMOVE
",
com.w.sdkService.services.callback.PublisherCallbackWithLog@56f6d40b
);
-> at com.w.sdkService.servlets.SdkPollerServlet.publishAddPartnersRequests(SdkPollerServlet.java:101)
How should I verify the call otherwise?
While debugging it never reaches my matchesSafely
method:
public class RequestMatcher extends TypeSafeMatcher<WazeSdkRequest.SdkRequest> {
private WazeSdkRequest.SdkRequest expectedRequest;
private RequestMatcher(final SdkRequest.SdkRequest request) {
this.expectedRequest = request;
}
@Override
protected boolean matchesSafely(final SdkRequest.SdkRequest sentRequest) {
boolean answer = SdkRequest.newBuilder(sentRequest).clearRequestId().build()
.equals(SdkRequest.newBuilder(expectedRequest).clearRequestId().build());
return answer;
}
public static RequestMatcher eqWithoutRequestId(final SdkRequest request) {
return new RequestMatcher(request);
}
@Override
public void describeTo(final Description description) {
}