HurlStack extends BaseHttpStack { @SuppressWarnings("deprecation") static void setConnectionParametersForRequest( HttpURLConnection connection, Request<?> request) throws IOException, AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: byte[] postBody = request.getPostBody(); if (postBody != null) { connection.setRequestMethod("POST"); addBody(connection, request, postBody); } break; case Method.GET: connection.setRequestMethod("GET"); break; case Method.DELETE: connection.setRequestMethod("DELETE"); break; case Method.POST: connection.setRequestMethod("POST"); addBodyIfExists(connection, request); break; case Method.PUT: connection.setRequestMethod("PUT"); addBodyIfExists(connection, request); break; case Method.HEAD: connection.setRequestMethod("HEAD"); break; case Method.OPTIONS: connection.setRequestMethod("OPTIONS"); break; case Method.TRACE: connection.setRequestMethod("TRACE"); break; case Method.PATCH: connection.setRequestMethod("PATCH"); addBodyIfExists(connection, request); break; default: throw new IllegalStateException("Unknown method type."); } } HurlStack();  HurlStack(UrlRewriter urlRewriter);  HurlStack(UrlRewriter urlRewriter, SSLSocketFactory sslSocketFactory); @Override HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders);  }
@Test public void connectionForDeprecatedGetRequest() throws Exception { TestRequest.DeprecatedGet request = new TestRequest.DeprecatedGet(); assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection, never()).setRequestMethod(anyString()); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForDeprecatedPostRequest() throws Exception { TestRequest.DeprecatedPost request = new TestRequest.DeprecatedPost(); assertEquals(request.getMethod(), Method.DEPRECATED_GET_OR_POST); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("POST"); verify(mMockConnection).setDoOutput(true); }
@Test public void connectionForGetRequest() throws Exception { TestRequest.Get request = new TestRequest.Get(); assertEquals(request.getMethod(), Method.GET); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("GET"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForPostRequest() throws Exception { TestRequest.Post request = new TestRequest.Post(); assertEquals(request.getMethod(), Method.POST); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("POST"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForPostWithBodyRequest() throws Exception { TestRequest.PostWithBody request = new TestRequest.PostWithBody(); assertEquals(request.getMethod(), Method.POST); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("POST"); verify(mMockConnection).setDoOutput(true); }
@Test public void connectionForPutRequest() throws Exception { TestRequest.Put request = new TestRequest.Put(); assertEquals(request.getMethod(), Method.PUT); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("PUT"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForPutWithBodyRequest() throws Exception { TestRequest.PutWithBody request = new TestRequest.PutWithBody(); assertEquals(request.getMethod(), Method.PUT); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("PUT"); verify(mMockConnection).setDoOutput(true); }
@Test public void connectionForDeleteRequest() throws Exception { TestRequest.Delete request = new TestRequest.Delete(); assertEquals(request.getMethod(), Method.DELETE); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("DELETE"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForHeadRequest() throws Exception { TestRequest.Head request = new TestRequest.Head(); assertEquals(request.getMethod(), Method.HEAD); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("HEAD"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForOptionsRequest() throws Exception { TestRequest.Options request = new TestRequest.Options(); assertEquals(request.getMethod(), Method.OPTIONS); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("OPTIONS"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForTraceRequest() throws Exception { TestRequest.Trace request = new TestRequest.Trace(); assertEquals(request.getMethod(), Method.TRACE); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("TRACE"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForPatchRequest() throws Exception { TestRequest.Patch request = new TestRequest.Patch(); assertEquals(request.getMethod(), Method.PATCH); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("PATCH"); verify(mMockConnection, never()).setDoOutput(true); }
@Test public void connectionForPatchWithBodyRequest() throws Exception { TestRequest.PatchWithBody request = new TestRequest.PatchWithBody(); assertEquals(request.getMethod(), Method.PATCH); HurlStack.setConnectionParametersForRequest(mMockConnection, request); verify(mMockConnection).setRequestMethod("PATCH"); verify(mMockConnection).setDoOutput(true); }