Polish
This commit is contained in:
parent
b5c9afc055
commit
9f6c5e4e39
|
@ -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()) {
|
||||
return OUTCOME_INFORMATIONAL;
|
||||
}
|
||||
if (status.is2xxSuccessful()) {
|
||||
return OUTCOME_SUCCESS;
|
||||
}
|
||||
if (status.is3xxRedirection()) {
|
||||
return OUTCOME_REDIRECTION;
|
||||
}
|
||||
if (status.is4xxClientError()) {
|
||||
return OUTCOME_CLIENT_ERROR;
|
||||
}
|
||||
if (status.is5xxServerError()) {
|
||||
return OUTCOME_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
return OUTCOME_UNKNOWN;
|
||||
}
|
||||
|
||||
private static HttpStatus extractStatus(ClientHttpResponse response) {
|
||||
try {
|
||||
if (response != null) {
|
||||
return response.getStatusCode();
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
if (statusCode.is1xxInformational()) {
|
||||
return OUTCOME_INFORMATIONAL;
|
||||
}
|
||||
if (statusCode.is2xxSuccessful()) {
|
||||
return OUTCOME_SUCCESS;
|
||||
}
|
||||
if (statusCode.is3xxRedirection()) {
|
||||
return OUTCOME_REDIRECTION;
|
||||
}
|
||||
if (statusCode.is4xxClientError()) {
|
||||
return OUTCOME_CLIENT_ERROR;
|
||||
}
|
||||
if (statusCode.is5xxServerError()) {
|
||||
return OUTCOME_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return OUTCOME_UNKNOWN;
|
||||
}
|
||||
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…
Reference in New Issue