Skip to content

Commit 0b168fb

Browse files
committed
Refactored boundary variables to be static attributes.
1 parent 3eebaa8 commit 0b168fb

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

gcloud-java-dns/src/main/java/com/google/cloud/dns/testing/LocalDnsHelper.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ public class LocalDnsHelper {
119119
private static final ScheduledExecutorService EXECUTORS =
120120
Executors.newScheduledThreadPool(2, Executors.defaultThreadFactory());
121121
private static final String PROJECT_ID = "dummyprojectid";
122+
private static final String responseBoundary = "____THIS_IS_HELPERS_BOUNDARY____";
123+
private static final String responseSeparator = new StringBuilder("--")
124+
.append(responseBoundary)
125+
.append("\r\n")
126+
.toString();
127+
private static final String responseEnd = new StringBuilder("--")
128+
.append(responseBoundary)
129+
.append("--\r\n\r\n")
130+
.toString();
122131

123132
static {
124133
try {
@@ -356,15 +365,6 @@ private Response handleBatch(final HttpExchange exchange) throws IOException {
356365
String contentType = exchange.getRequestHeaders().getFirst("Content-type");
357366
if (contentType != null) {
358367
int port = server.getAddress().getPort();
359-
String responseBoundary = "____THIS_IS_HELPERS_BOUNDARY____";
360-
String responseSeparator = new StringBuilder("--")
361-
.append(responseBoundary)
362-
.append("\r\n")
363-
.toString();
364-
String responseEnd = new StringBuilder("--")
365-
.append(responseBoundary)
366-
.append("--\r\n\r\n")
367-
.toString();
368368
HttpMediaType httpMediaType = new HttpMediaType(contentType);
369369
String boundary = httpMediaType.getParameter("boundary");
370370
MultipartStream multipartStream =
@@ -412,7 +412,7 @@ private Response handleBatch(final HttpExchange exchange) throws IOException {
412412
}
413413
}
414414
out.write(responseEnd.getBytes());
415-
writeBatchResponse(exchange, out, responseBoundary);
415+
writeBatchResponse(exchange, out);
416416
}
417417
return null;
418418
}
@@ -520,11 +520,10 @@ private static void writeResponse(HttpExchange exchange, Response response) {
520520
}
521521
}
522522

523-
private static void writeBatchResponse(HttpExchange exchange, ByteArrayOutputStream out,
524-
String boundary) {
525-
exchange.getResponseHeaders().set("Content-type", "multipart/mixed; boundary=" + boundary);
523+
private static void writeBatchResponse(HttpExchange exchange, ByteArrayOutputStream out) {
524+
exchange.getResponseHeaders().set(
525+
"Content-type", "multipart/mixed; boundary=" + responseBoundary);
526526
try {
527-
exchange.getResponseHeaders().add("Connection", "close");
528527
exchange.getResponseHeaders().add("Connection", "close");
529528
exchange.sendResponseHeaders(200, out.toByteArray().length);
530529
OutputStream responseBody = exchange.getResponseBody();

gcloud-java-dns/src/test/java/com/google/cloud/dns/testing/LocalDnsHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ public void onFailure(GoogleJsonError googleJsonError) {
29132913
batch.addGetChangeRequest(created.getName(), "0", new RpcBatch.Callback<Change>() {
29142914
@Override
29152915
public void onSuccess(Change response) {
2916-
assertEquals(RPC.getChangeRequest(created.getName(), "0", EMPTY_RPC_OPTIONS),response);
2916+
assertEquals(RPC.getChangeRequest(created.getName(), "0", EMPTY_RPC_OPTIONS), response);
29172917
}
29182918

29192919
@Override

0 commit comments

Comments
 (0)