Skip to content

Commit 00f9aea

Browse files
committed
Remove a class of our which replicates HTTP status codes already given meaningful names in the standard JRE.
1 parent c9ccf2a commit 00f9aea

File tree

5 files changed

+18
-40
lines changed

5 files changed

+18
-40
lines changed

java/client/src/org/openqa/selenium/remote/build.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ java_library(name = "remote",
102102
"http/HttpMethod.java",
103103
"http/HttpRequest.java",
104104
"http/HttpResponse.java",
105-
"http/HttpStatusCodes.java",
106105
"http/JsonHttpCommandCodec.java",
107106
"http/JsonHttpResponseCodec.java",
108107
"internal/CircularOutputStream.java",

java/client/src/org/openqa/selenium/remote/http/HttpResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package org.openqa.selenium.remote.http;
1919

20+
import static java.net.HttpURLConnection.HTTP_OK;
21+
2022
public class HttpResponse extends HttpMessage {
2123

22-
private int status = HttpStatusCodes.OK;
24+
private int status = HTTP_OK;
2325

2426
public int getStatus() {
2527
return status;

java/client/src/org/openqa/selenium/remote/http/HttpStatusCodes.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

java/client/src/org/openqa/selenium/remote/http/JsonHttpResponseCodec.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
88
import static com.google.common.net.HttpHeaders.EXPIRES;
99
import static com.google.common.net.MediaType.JSON_UTF_8;
10+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
11+
import static java.net.HttpURLConnection.HTTP_OK;
1012

1113
import org.openqa.selenium.remote.BeanToJsonConverter;
1214
import org.openqa.selenium.remote.ErrorCodes;
@@ -36,8 +38,8 @@ public class JsonHttpResponseCodec implements ResponseCodec<HttpResponse> {
3638
@Override
3739
public HttpResponse encode(Response response) {
3840
int status = response.getStatus() == ErrorCodes.SUCCESS
39-
? HttpStatusCodes.OK
40-
: HttpStatusCodes.INTERNAL_SERVER_ERROR;
41+
? HTTP_OK
42+
: HTTP_INTERNAL_ERROR;
4143

4244
byte[] data = beanToJsonConverter.convert(response).getBytes(UTF_8);
4345

java/client/test/org/openqa/selenium/remote/http/JsonHttpResponseCodecTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import static com.google.common.base.Charsets.UTF_8;
55
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
66
import static com.google.common.net.MediaType.JSON_UTF_8;
7+
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
8+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
9+
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
10+
import static java.net.HttpURLConnection.HTTP_OK;
711
import static org.hamcrest.Matchers.is;
812
import static org.junit.Assert.assertEquals;
913
import static org.junit.Assert.assertNull;
@@ -35,7 +39,7 @@ public void convertsResponses_success() throws JSONException {
3539
response.setValue(ImmutableMap.of("color", "red"));
3640

3741
HttpResponse converted = codec.encode(response);
38-
assertThat(converted.getStatus(), is(HttpStatusCodes.OK));
42+
assertThat(converted.getStatus(), is(HTTP_OK));
3943
assertThat(converted.getHeader(CONTENT_TYPE), is(JSON_UTF_8.toString()));
4044

4145
Response rebuilt = new JsonToBeanConverter().convert(
@@ -54,7 +58,7 @@ public void convertsResponses_failure() throws JSONException {
5458
response.setValue(ImmutableMap.of("color", "red"));
5559

5660
HttpResponse converted = codec.encode(response);
57-
assertThat(converted.getStatus(), is(HttpStatusCodes.INTERNAL_SERVER_ERROR));
61+
assertThat(converted.getStatus(), is(HTTP_INTERNAL_ERROR));
5862
assertThat(converted.getHeader(CONTENT_TYPE), is(JSON_UTF_8.toString()));
5963

6064
Response rebuilt = new JsonToBeanConverter().convert(
@@ -83,7 +87,7 @@ public void roundTrip() throws JSONException {
8387
@Test
8488
public void decodeNonJsonResponse_200() throws JSONException {
8589
HttpResponse response = new HttpResponse();
86-
response.setStatus(HttpStatusCodes.OK);
90+
response.setStatus(HTTP_OK);
8791
response.setContent("foobar".getBytes(UTF_8));
8892

8993
Response decoded = codec.decode(response);
@@ -94,7 +98,7 @@ public void decodeNonJsonResponse_200() throws JSONException {
9498
@Test
9599
public void decodeNonJsonResponse_204() throws JSONException {
96100
HttpResponse response = new HttpResponse();
97-
response.setStatus(HttpStatusCodes.NO_CONTENT);
101+
response.setStatus(HTTP_NO_CONTENT);
98102

99103
Response decoded = codec.decode(response);
100104
assertEquals(ErrorCodes.SUCCESS, decoded.getStatus());
@@ -104,7 +108,7 @@ public void decodeNonJsonResponse_204() throws JSONException {
104108
@Test
105109
public void decodeNonJsonResponse_4xx() throws JSONException {
106110
HttpResponse response = new HttpResponse();
107-
response.setStatus(HttpStatusCodes.BAD_REQUEST);
111+
response.setStatus(HTTP_BAD_REQUEST);
108112
response.setContent("foobar".getBytes(UTF_8));
109113

110114
Response decoded = codec.decode(response);
@@ -115,7 +119,7 @@ public void decodeNonJsonResponse_4xx() throws JSONException {
115119
@Test
116120
public void decodeNonJsonResponse_5xx() throws JSONException {
117121
HttpResponse response = new HttpResponse();
118-
response.setStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR);
122+
response.setStatus(HTTP_INTERNAL_ERROR);
119123
response.setContent("foobar".getBytes(UTF_8));
120124

121125
Response decoded = codec.decode(response);
@@ -130,7 +134,7 @@ public void decodeJsonResponseMissingContentType() throws JSONException {
130134
response.setValue(ImmutableMap.of("color", "red"));
131135

132136
HttpResponse httpResponse = new HttpResponse();
133-
httpResponse.setStatus(HttpStatusCodes.OK);
137+
httpResponse.setStatus(HTTP_OK);
134138
httpResponse.setContent(
135139
new BeanToJsonConverter().convert(response).getBytes(UTF_8));
136140

0 commit comments

Comments
 (0)