Skip to content

Commit aae3a3e

Browse files
author
Yaniv Inbar
committed
[http] update mocks IOException -> Exception
https://codereview.appspot.com/6500124/
1 parent 6dcae3f commit aae3a3e

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

google-http-client/src/main/java/com/google/api/client/http/HttpContent.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public interface HttpContent {
5050
* Writes the content to the given output stream.
5151
*
5252
* <p>
53-
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
54-
* {@link java.io.IOException}.
55-
* </p>
56-
*
57-
* <p>
5853
* The recommendation for implementations is that they should not close the output stream. Callers
5954
* should not assume whether or not the output stream has been closed. Implementations that do not
6055
* close the output stream should flush it at the end of the method.
6156
* </p>
57+
*
58+
* <p>
59+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
60+
* {@link java.io.IOException}.
61+
* </p>
6262
*/
6363
void writeTo(OutputStream out) throws Exception;
6464

google-http-client/src/main/java/com/google/api/client/testing/http/MockHttpContent.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.api.client.http.HttpContent;
1818
import com.google.common.base.Preconditions;
1919

20-
import java.io.IOException;
2120
import java.io.OutputStream;
2221

2322
/**
@@ -48,15 +47,27 @@ public String getEncoding() {
4847
return encoding;
4948
}
5049

51-
public long getLength() throws IOException {
50+
/**
51+
* <p>
52+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
53+
* {@link java.io.IOException}.
54+
* </p>
55+
*/
56+
public long getLength() throws Exception {
5257
return length;
5358
}
5459

5560
public String getType() {
5661
return type;
5762
}
5863

59-
public void writeTo(OutputStream out) throws IOException {
64+
/**
65+
* <p>
66+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
67+
* {@link java.io.IOException}.
68+
* </p>
69+
*/
70+
public void writeTo(OutputStream out) throws Exception {
6071
out.write(content);
6172
out.flush();
6273
}

google-http-client/src/main/java/com/google/api/client/testing/http/MockHttpUnsuccessfulResponseHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.google.api.client.http.HttpResponse;
1919
import com.google.api.client.http.HttpUnsuccessfulResponseHandler;
2020

21-
import java.io.IOException;
22-
2321
/**
2422
* Mock for {@link HttpUnsuccessfulResponseHandler}.
2523
*
@@ -51,8 +49,14 @@ public boolean isCalled() {
5149
return isCalled;
5250
}
5351

52+
/**
53+
* <p>
54+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
55+
* {@link java.io.IOException}.
56+
* </p>
57+
*/
5458
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)
55-
throws IOException {
59+
throws Exception {
5660
isCalled = true;
5761
return successfullyHandleResponse;
5862
}

google-http-client/src/main/java/com/google/api/client/testing/http/MockLowLevelHttpRequest.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.api.client.http.LowLevelHttpRequest;
1919
import com.google.api.client.http.LowLevelHttpResponse;
2020

21-
import java.io.IOException;
2221
import java.util.ArrayList;
2322
import java.util.HashMap;
2423
import java.util.List;
@@ -65,8 +64,14 @@ public MockLowLevelHttpRequest(String url) {
6564
this.url = url;
6665
}
6766

67+
/**
68+
* <p>
69+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it did not
70+
* throw an exception.
71+
* </p>
72+
*/
6873
@Override
69-
public void addHeader(String name, String value) {
74+
public void addHeader(String name, String value) throws Exception {
7075
List<String> values = headersMap.get(name);
7176
if (values == null) {
7277
values = new ArrayList<String>();
@@ -75,13 +80,25 @@ public void addHeader(String name, String value) {
7580
values.add(value);
7681
}
7782

83+
/**
84+
* <p>
85+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
86+
* {@link java.io.IOException}.
87+
* </p>
88+
*/
7889
@Override
79-
public LowLevelHttpResponse execute() throws IOException {
90+
public LowLevelHttpResponse execute() throws Exception {
8091
return response;
8192
}
8293

94+
/**
95+
* <p>
96+
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
97+
* {@link java.io.IOException}.
98+
* </p>
99+
*/
83100
@Override
84-
public void setContent(HttpContent content) throws IOException {
101+
public void setContent(HttpContent content) throws Exception {
85102
this.content = content;
86103
}
87104

google-http-client/src/test/java/com/google/api/client/http/HttpRequestTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
697697
return new MockLowLevelHttpRequest() {
698698

699699
@Override
700-
public void setContent(HttpContent content) throws IOException {
700+
public void setContent(HttpContent content) throws Exception {
701701
if (expectGZip) {
702702
assertEquals(GZipContent.class, content.getClass());
703703
assertEquals("gzip", content.getEncoding());
@@ -734,7 +734,7 @@ class MyTransport extends MockHttpTransport {
734734
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
735735
return new MockLowLevelHttpRequest() {
736736
@Override
737-
public void setContent(HttpContent content) throws IOException {
737+
public void setContent(HttpContent content) throws Exception {
738738
if (expectLogContent) {
739739
assertEquals(LogContent.class, content.getClass());
740740
} else {
@@ -809,7 +809,7 @@ class MyTransport extends MockHttpTransport {
809809
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
810810
return new MockLowLevelHttpRequest() {
811811
@Override
812-
public LowLevelHttpResponse execute() throws IOException {
812+
public LowLevelHttpResponse execute() throws Exception {
813813
List<String> userAgents = getHeaders().get("User-Agent");
814814
String actualUserAgent = userAgents == null ? null : userAgents.get(0);
815815
assertEquals(expectedUserAgent, actualUserAgent);

0 commit comments

Comments
 (0)