Merge pull request #15799 from Johnny Lim

* gh-15799:
  Polish

Closes gh-15799
pull/17858/head
Andy Wilkinson 6 years ago
commit 5c08e23e9b

@ -131,43 +131,36 @@ public final class RestTemplateExchangeTags {
}
/**
* Creates a {@code outcome} {@code Tag} derived from the
* Creates an {@code outcome} {@code Tag} derived from the
* {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}.
* @param response the response
* @return the outcome tag
* @since 2.2.0
*/
public static Tag outcome(ClientHttpResponse response) {
HttpStatus status = extractStatus(response);
if (status != null) {
if (status.is1xxInformational()) {
try {
if (response != null) {
HttpStatus statusCode = response.getStatusCode();
if (statusCode.is1xxInformational()) {
return OUTCOME_INFORMATIONAL;
}
if (status.is2xxSuccessful()) {
if (statusCode.is2xxSuccessful()) {
return OUTCOME_SUCCESS;
}
if (status.is3xxRedirection()) {
if (statusCode.is3xxRedirection()) {
return OUTCOME_REDIRECTION;
}
if (status.is4xxClientError()) {
if (statusCode.is4xxClientError()) {
return OUTCOME_CLIENT_ERROR;
}
if (status.is5xxServerError()) {
if (statusCode.is5xxServerError()) {
return OUTCOME_SERVER_ERROR;
}
}
return OUTCOME_UNKNOWN;
}
private static HttpStatus extractStatus(ClientHttpResponse response) {
try {
if (response != null) {
return response.getStatusCode();
}
return null;
}
catch (IOException | IllegalArgumentException exc) {
return null;
catch (IOException | IllegalArgumentException ex) {
return OUTCOME_UNKNOWN;
}
}

@ -126,7 +126,7 @@ public final class WebClientExchangeTags {
}
/**
* Creates a {@code outcome} {@code Tag} derived from the
* Creates an {@code outcome} {@code Tag} derived from the
* {@link ClientResponse#statusCode() status} of the given {@code response}.
* @param response the response
* @return the outcome tag

@ -34,12 +34,11 @@ import static org.mockito.Mockito.mock;
*
* @author Nishant Raut
* @author Brian Clozel
* @author Brian Clozel
*/
public class RestTemplateExchangeTagsTests {
@Test
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
public void outcomeTagIsUnknownWhenResponseIsNull() {
Tag tag = RestTemplateExchangeTags.outcome(null);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}

@ -34,7 +34,7 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link WebClientExchangeTags}
* Tests for {@link WebClientExchangeTags}.
*
* @author Brian Clozel
* @author Nishant Raut
@ -115,7 +115,7 @@ public class WebClientExchangeTagsTests {
}
@Test
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
public void outcomeTagIsUnknownWhenResponseIsNull() {
Tag tag = WebClientExchangeTags.outcome(null);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@ -156,7 +156,7 @@ public class WebClientExchangeTagsTests {
}
@Test
public void outcomeTagIsUknownWhenResponseStatusIsUknown() {
public void outcomeTagIsUnknownWhenResponseStatusIsUnknown() {
given(this.response.statusCode()).willThrow(IllegalArgumentException.class);
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");

Loading…
Cancel
Save