Merge pull request #127 from panchenko/empty_reason_phrase_master
replace empty HttpResponseException.message with statusCode
This commit is contained in:
commit
59ee896faa
|
@ -26,6 +26,8 @@
|
|||
*/
|
||||
package org.apache.hc.client5.http;
|
||||
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
|
||||
/**
|
||||
* Signals a non 2xx HTTP response.
|
||||
*
|
||||
|
@ -38,7 +40,7 @@ public class HttpResponseException extends ClientProtocolException {
|
|||
private final int statusCode;
|
||||
|
||||
public HttpResponseException(final int statusCode, final String s) {
|
||||
super(s);
|
||||
super(TextUtils.isBlank(s) ? Integer.toString(statusCode) : s);
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ public class TestAbstractHttpClientResponseHandler {
|
|||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
|
||||
Mockito.when(response.getCode()).thenReturn(404);
|
||||
Mockito.when(response.getReasonPhrase()).thenReturn("NOT FOUND");
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
|
||||
final BasicHttpClientResponseHandler handler = new BasicHttpClientResponseHandler();
|
||||
|
@ -79,9 +80,32 @@ public class TestAbstractHttpClientResponseHandler {
|
|||
Assert.fail("HttpResponseException expected");
|
||||
} catch (final HttpResponseException ex) {
|
||||
Assert.assertEquals(404, ex.getStatusCode());
|
||||
Assert.assertEquals("NOT FOUND", ex.getMessage());
|
||||
}
|
||||
Mockito.verify(entity).getContent();
|
||||
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 ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
|
||||
Mockito.when(response.getCode()).thenReturn(404);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
|
||||
final BasicHttpClientResponseHandler handler = new BasicHttpClientResponseHandler();
|
||||
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…
Reference in New Issue