mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-18 16:07:11 +00:00
replace empty HttpResponseException.message with statusCode
This commit is contained in:
parent
a0c20ec14d
commit
20dfff12c4
@ -26,6 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.http.client;
|
package org.apache.http.client;
|
||||||
|
|
||||||
|
import org.apache.http.util.TextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signals a non 2xx HTTP response.
|
* Signals a non 2xx HTTP response.
|
||||||
*
|
*
|
||||||
@ -38,7 +40,7 @@ public class HttpResponseException extends ClientProtocolException {
|
|||||||
private final int statusCode;
|
private final int statusCode;
|
||||||
|
|
||||||
public HttpResponseException(final int statusCode, final String s) {
|
public HttpResponseException(final int statusCode, final String s) {
|
||||||
super(s);
|
super(TextUtils.isBlank(s) ? Integer.toString(statusCode) : s);
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,4 +90,27 @@ public void testUnsuccessfulResponse() throws Exception {
|
|||||||
Mockito.verify(inStream).close();
|
Mockito.verify(inStream).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("boxing")
|
||||||
|
@Test
|
||||||
|
public void testUnsuccessfulResponseEmptyReason() throws Exception {
|
||||||
|
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||||
|
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||||
|
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||||
|
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||||
|
final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "");
|
||||||
|
final HttpResponse response = Mockito.mock(HttpResponse.class);
|
||||||
|
Mockito.when(response.getStatusLine()).thenReturn(sl);
|
||||||
|
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||||
|
|
||||||
|
final BasicResponseHandler handler = new BasicResponseHandler();
|
||||||
|
try {
|
||||||
|
handler.handleResponse(response);
|
||||||
|
Assert.fail("HttpResponseException expected");
|
||||||
|
} catch (final HttpResponseException ex) {
|
||||||
|
Assert.assertEquals(404, ex.getStatusCode());
|
||||||
|
Assert.assertEquals("404", ex.getMessage());
|
||||||
|
}
|
||||||
|
Mockito.verify(entity).getContent();
|
||||||
|
Mockito.verify(inStream).close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user