@@ -183,6 +183,62 @@ public LowLevelHttpResponse execute() throws IOException {
183
183
}
184
184
}
185
185
186
+ public void testInvalidCharset () throws Exception {
187
+ HttpTransport transport = new MockHttpTransport () {
188
+ @ Override
189
+ public LowLevelHttpRequest buildRequest (String method , String url ) throws IOException {
190
+ return new MockLowLevelHttpRequest () {
191
+ @ Override
192
+ public LowLevelHttpResponse execute () throws IOException {
193
+ MockLowLevelHttpResponse result = new MockLowLevelHttpResponse ();
194
+ result .setStatusCode (HttpStatusCodes .STATUS_CODE_NOT_FOUND );
195
+ result .setReasonPhrase ("Not Found" );
196
+ result .setContentType ("text/plain; charset=" );
197
+ result .setContent ("Unable to find resource" );
198
+ return result ;
199
+ }
200
+ };
201
+ }
202
+ };
203
+ HttpRequest request =
204
+ transport .createRequestFactory ().buildGetRequest (HttpTesting .SIMPLE_GENERIC_URL );
205
+ try {
206
+ request .execute ();
207
+ fail ();
208
+ } catch (HttpResponseException e ) {
209
+ assertEquals (
210
+ "404 Not Found" , e .getMessage ());
211
+ }
212
+ }
213
+
214
+ public void testUnsupportedCharset () throws Exception {
215
+ HttpTransport transport = new MockHttpTransport () {
216
+ @ Override
217
+ public LowLevelHttpRequest buildRequest (String method , String url ) throws IOException {
218
+ return new MockLowLevelHttpRequest () {
219
+ @ Override
220
+ public LowLevelHttpResponse execute () throws IOException {
221
+ MockLowLevelHttpResponse result = new MockLowLevelHttpResponse ();
222
+ result .setStatusCode (HttpStatusCodes .STATUS_CODE_NOT_FOUND );
223
+ result .setReasonPhrase ("Not Found" );
224
+ result .setContentType ("text/plain; charset=invalid-charset" );
225
+ result .setContent ("Unable to find resource" );
226
+ return result ;
227
+ }
228
+ };
229
+ }
230
+ };
231
+ HttpRequest request =
232
+ transport .createRequestFactory ().buildGetRequest (HttpTesting .SIMPLE_GENERIC_URL );
233
+ try {
234
+ request .execute ();
235
+ fail ();
236
+ } catch (HttpResponseException e ) {
237
+ assertEquals (
238
+ "404 Not Found" , e .getMessage ());
239
+ }
240
+ }
241
+
186
242
public void testSerialization () throws Exception {
187
243
HttpTransport transport = new MockHttpTransport ();
188
244
HttpRequest request =
0 commit comments