Improve message for HttpStatusCodeException with empty status text

This commit improves the message for HttpStatusCodeException so that it
defaults to the HttpStatus reason phrase if a status text is not
provided.

This commit also fixes SimpleClientHttpResponse so that it does not
return null for getStatusText().

Fixed #22162
This commit is contained in:
Arjen Poutsma
2019-01-23 11:42:55 +01:00
parent 155ef5fd77
commit a5cef3845c
3 changed files with 21 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import org.junit.Test;
import org.springframework.http.HttpStatus;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
/**
@@ -54,4 +54,11 @@ public class HttpStatusCodeExceptionTests {
assertThat(ex2.getResponseBodyAsString(), equalTo(ex1.getResponseBodyAsString()));
}
@Test
public void emptyStatusText() {
HttpStatusCodeException ex = new HttpClientErrorException(HttpStatus.NOT_FOUND, "");
assertEquals("404 Not Found", ex.getMessage());
}
}