expect tests: removing requirement that requests are unique (so orderedRequestsSendResponses can tee up different responses for the same request when testing functions)

This commit is contained in:
Adam Lowe 2012-07-17 15:30:03 +01:00
parent 01f121a654
commit 20d3d0d603
1 changed files with 4 additions and 4 deletions

View File

@ -80,7 +80,6 @@ import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -440,13 +439,14 @@ public abstract class BaseRestApiExpectTest<S> {
public S requestsSendResponses(final Map<HttpRequest, HttpResponse> requestToResponse, Module module,
Properties props) {
return createClient(new Function<HttpRequest, HttpResponse>() {
ImmutableBiMap<HttpRequest, HttpResponse> bimap = ImmutableBiMap.copyOf(requestToResponse);
@Override
public HttpResponse apply(HttpRequest input) {
HttpRequest matchedRequest = null;
HttpResponse response = null;
for (HttpRequest request : requestToResponse.keySet()) {
if (httpRequestsAreEqual(input, request)) {
matchedRequest = request;
response = requestToResponse.get(request);
}
}
@ -467,7 +467,7 @@ public abstract class BaseRestApiExpectTest<S> {
} else if (compareHttpRequestAsType(input) == HttpRequestComparisonType.DEFAULT) {
// in case hashCode/equals doesn't do a full content check
assertEquals(renderRequest(input), renderRequest(bimap.inverse().get(response)));
assertEquals(renderRequest(input), renderRequest(matchedRequest));
}
return response;