All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.libs.ws.DummyWSClient Maven / Gradle / Ivy

There is a newer version: 2.6.2
Show newest version
package play.libs.ws;

import static java.util.Collections.emptyMap;

import java.util.HashMap;
import java.util.Map;

public class DummyWSClient extends WSAsync {
  private final Map> requests = new HashMap<>();
  private final Map> responses = new HashMap<>();

  public void replyWith(String url, HttpMethod method, int status, String body) {
    this.responses
        .computeIfAbsent(url, u -> new HashMap<>())
        .put(method, new DummyHttpResponse(status, body));
  }

  @Override
  public WSRequest newRequest(String url) {
    return new DummyWSRequest(url, requests, responses);
  }

  public DummyWSRequest actualRequest(String url, HttpMethod method) {
    return requests.getOrDefault(url, emptyMap()).get(method);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy