MockExchangeFunction Support Multiple Requests

Issue: gh-5386
This commit is contained in:
Rob Winch 2018-07-02 10:00:06 -05:00
parent e27e1cd637
commit 0910e04bdf
1 changed files with 11 additions and 3 deletions

View File

@ -24,23 +24,31 @@ import org.springframework.web.reactive.function.client.ExchangeFunction;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author Rob Winch * @author Rob Winch
* @since 5.1 * @since 5.1
*/ */
public class MockExchangeFunction implements ExchangeFunction { public class MockExchangeFunction implements ExchangeFunction {
private ClientRequest request; private List<ClientRequest> requests = new ArrayList<>();
private ClientResponse response = mock(ClientResponse.class); private ClientResponse response = mock(ClientResponse.class);
public ClientRequest getRequest() { public ClientRequest getRequest() {
return this.request; return this.requests.get(this.requests.size() - 1);
}
public List<ClientRequest> getRequests() {
return this.requests;
}
} }
@Override @Override
public Mono<ClientResponse> exchange(ClientRequest request) { public Mono<ClientResponse> exchange(ClientRequest request) {
return Mono.defer(() -> { return Mono.defer(() -> {
this.request = request; this.requests.add(request);
return Mono.just(this.response); return Mono.just(this.response);
}); });
} }