From 61a5ec8fddf21619ff2c91035013ad72759ed438 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Thu, 11 Feb 2021 03:20:07 -0800 Subject: [PATCH 1/6] fix: fix buildRequest setUrl order --- .../java/com/google/api/client/http/HttpRequestFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-http-client/src/main/java/com/google/api/client/http/HttpRequestFactory.java b/google-http-client/src/main/java/com/google/api/client/http/HttpRequestFactory.java index a14058c8b..7a92a03bf 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/HttpRequestFactory.java +++ b/google-http-client/src/main/java/com/google/api/client/http/HttpRequestFactory.java @@ -84,13 +84,13 @@ public HttpRequestInitializer getInitializer() { public HttpRequest buildRequest(String requestMethod, GenericUrl url, HttpContent content) throws IOException { HttpRequest request = transport.buildRequest(); + if (url != null) { + request.setUrl(url); + } if (initializer != null) { initializer.initialize(request); } request.setRequestMethod(requestMethod); - if (url != null) { - request.setUrl(url); - } if (content != null) { request.setContent(content); } From 9a02c9239824e5012daf331ccf303c45eb2b4079 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Thu, 11 Feb 2021 16:45:13 -0800 Subject: [PATCH 2/6] chore: add unit test --- .../client/http/HttpRequestFactoryTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java new file mode 100644 index 000000000..93e217e37 --- /dev/null +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.api.client.http; + +import com.google.api.client.http.javanet.NetHttpTransport; + +import junit.framework.TestCase; + +/** + * Tests {@link HttpRequestFactory}. + */ +public class HttpRequestFactoryTest extends TestCase { + + public void testBuildRequest_urlShouldBeSet() throws Exception { + HttpRequestFactory requestFactory = + new NetHttpTransport().createRequestFactory( + new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest request) { + // Url should be set by buildRequest method before calling initialize. + if (request.getUrl() == null) { + throw new IllegalArgumentException("url is not set in request"); + } + } + }); + GenericUrl url = new GenericUrl("https://foo.googleapis.com/"); + HttpRequest request = requestFactory.buildRequest("GET", url, null); + assertEquals(url, request.getUrl()); + } +} From b68464d0518e286ded927b5ed86de8ff7ff4c605 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Thu, 11 Feb 2021 16:47:00 -0800 Subject: [PATCH 3/6] update --- .../com/google/api/client/http/HttpRequestFactoryTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java index 93e217e37..8acd431c0 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java @@ -14,6 +14,8 @@ package com.google.api.client.http; +import java.io.IOException; + import com.google.api.client.http.javanet.NetHttpTransport; import junit.framework.TestCase; @@ -23,7 +25,7 @@ */ public class HttpRequestFactoryTest extends TestCase { - public void testBuildRequest_urlShouldBeSet() throws Exception { + public void testBuildRequest_urlShouldBeSet() throws IllegalArgumentException, IOException { HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory( new HttpRequestInitializer() { From cebac150854f7f91095a264e75c8eff64342c633 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Thu, 11 Feb 2021 16:59:57 -0800 Subject: [PATCH 4/6] format --- .../client/http/HttpRequestFactoryTest.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java index 8acd431c0..3efd35c8f 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java @@ -14,29 +14,26 @@ package com.google.api.client.http; -import java.io.IOException; - import com.google.api.client.http.javanet.NetHttpTransport; - +import java.io.IOException; import junit.framework.TestCase; -/** - * Tests {@link HttpRequestFactory}. - */ +/** Tests {@link HttpRequestFactory}. */ public class HttpRequestFactoryTest extends TestCase { public void testBuildRequest_urlShouldBeSet() throws IllegalArgumentException, IOException { HttpRequestFactory requestFactory = - new NetHttpTransport().createRequestFactory( - new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest request) { - // Url should be set by buildRequest method before calling initialize. - if (request.getUrl() == null) { - throw new IllegalArgumentException("url is not set in request"); - } - } - }); + new NetHttpTransport() + .createRequestFactory( + new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest request) { + // Url should be set by buildRequest method before calling initialize. + if (request.getUrl() == null) { + throw new IllegalArgumentException("url is not set in request"); + } + } + }); GenericUrl url = new GenericUrl("https://foo.googleapis.com/"); HttpRequest request = requestFactory.buildRequest("GET", url, null); assertEquals(url, request.getUrl()); From 1ed11073af4e7c2b8e68dc39cf14ffda60f79b44 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Fri, 12 Feb 2021 10:42:33 -0800 Subject: [PATCH 5/6] Update google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java --- .../java/com/google/api/client/http/HttpRequestFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java index 3efd35c8f..92793e43e 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Google Inc. + * Copyright 2021 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at From 48db3dde0d3687727636bb1b9d4c2a47bb8ac6a9 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Tue, 23 Feb 2021 17:18:01 -0800 Subject: [PATCH 6/6] Update google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java Co-authored-by: Jeff Ching --- .../java/com/google/api/client/http/HttpRequestFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java index 92793e43e..568eb201c 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Google Inc. + * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at