JavaApiConverter { public static Request createOkRequest( URI uri, String requestMethod, Map<String, List<String>> requestHeaders) { RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod) ? EMPTY_REQUEST_BODY : null; Request.Builder builder = new Request.Builder() .url(uri.toString()) .method(requestMethod, placeholderBody); if (requestHeaders != null) { Headers headers = extractOkHeaders(requestHeaders); builder.headers(headers); } return builder.build(); } private  JavaApiConverter(); static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection); static Request createOkRequest(
      URI uri, String requestMethod, Map<String, List<String>> requestHeaders); static CacheResponse createJavaCacheResponse(final Response response); static java.net.CacheRequest createJavaCacheRequest(final CacheRequest okCacheRequest);  }
@Test public void createOkRequest_nullRequestHeaders() throws Exception { URI uri = new URI("http: Map<String, List<String>> javaRequestHeaders = null; Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders); assertFalse(request.isHttps()); assertEquals(uri, request.url().uri()); Headers okRequestHeaders = request.headers(); assertEquals(0, okRequestHeaders.size()); assertEquals("POST", request.method()); }
@Test public void createOkRequest_nonNullRequestHeaders() throws Exception { URI uri = new URI("https: Map<String, List<String>> javaRequestHeaders = new HashMap<>(); javaRequestHeaders.put("Foo", Arrays.asList("Bar")); Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders); assertTrue(request.isHttps()); assertEquals(uri, request.url().uri()); Headers okRequestHeaders = request.headers(); assertEquals(1, okRequestHeaders.size()); assertEquals("Bar", okRequestHeaders.get("Foo")); assertEquals("POST", request.method()); }
@Test public void createOkRequest_nullRequestHeaderKey() throws Exception { URI uri = new URI("https: Map<String, List<String>> javaRequestHeaders = new HashMap<>(); javaRequestHeaders.put(null, Arrays.asList("GET / HTTP 1.1")); javaRequestHeaders.put("Foo", Arrays.asList("Bar")); Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders); assertTrue(request.isHttps()); assertEquals(uri, request.url().uri()); Headers okRequestHeaders = request.headers(); assertEquals(1, okRequestHeaders.size()); assertEquals("Bar", okRequestHeaders.get("Foo")); assertEquals("POST", request.method()); }