Skip to content

Commit

Permalink
Replace Guava's Charset with JDK builtin StandardCharsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
brcolow authored and jamesdbloom committed Feb 12, 2018
1 parent 570bdd6 commit 3b543ec
Show file tree
Hide file tree
Showing 67 changed files with 307 additions and 299 deletions.
@@ -1,6 +1,5 @@
package org.mockserver.client;

import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.SettableFuture;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -20,6 +19,7 @@
import org.mockserver.verify.VerificationTimes;

import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -189,7 +189,7 @@ public boolean isRunning(int attempts, long timeout, TimeUnit timeUnit) {
* Bind new ports to listen on
*/
public List<Integer> bind(Integer... ports) {
String boundPorts = sendRequest(request().withMethod("PUT").withPath(calculatePath("bind")).withBody(portBindingSerializer.serialize(portBinding(ports)), Charsets.UTF_8)).getBodyAsString();
String boundPorts = sendRequest(request().withMethod("PUT").withPath(calculatePath("bind")).withBody(portBindingSerializer.serialize(portBinding(ports)), StandardCharsets.UTF_8)).getBodyAsString();
return portBindingSerializer.deserialize(boundPorts).getPorts();
}

Expand Down Expand Up @@ -238,7 +238,7 @@ public MockServerClient reset() {
* @param httpRequest the http request that is matched against when deciding whether to clear each expectation if null all expectations are cleared
*/
public MockServerClient clear(HttpRequest httpRequest) {
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8));
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8));
return clientClass.cast(this);
}

Expand All @@ -249,7 +249,7 @@ public MockServerClient clear(HttpRequest httpRequest) {
* @param type the type to clear, EXPECTATION, LOG or BOTH
*/
public MockServerClient clear(HttpRequest httpRequest, ClearType type) {
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withQueryStringParameter("type", type.name().toLowerCase()).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8));
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withQueryStringParameter("type", type.name().toLowerCase()).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8));
return clientClass.cast(this);
}

Expand All @@ -276,7 +276,7 @@ public MockServerClient verify(HttpRequest... httpRequests) throws AssertionErro
}

VerificationSequence verificationSequence = new VerificationSequence().withRequests(httpRequests);
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verifySequence")).withBody(verificationSequenceSerializer.serialize(verificationSequence), Charsets.UTF_8)).getBodyAsString();
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verifySequence")).withBody(verificationSequenceSerializer.serialize(verificationSequence), StandardCharsets.UTF_8)).getBodyAsString();

if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
Expand Down Expand Up @@ -314,7 +314,7 @@ public MockServerClient verify(HttpRequest httpRequest, VerificationTimes times)
}

Verification verification = verification().withRequest(httpRequest).withTimes(times);
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), Charsets.UTF_8)).getBodyAsString();
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), StandardCharsets.UTF_8)).getBodyAsString();

if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
Expand All @@ -329,7 +329,7 @@ public MockServerClient verify(HttpRequest httpRequest, VerificationTimes times)
*/
public MockServerClient verifyZeroInteractions() throws AssertionError {
Verification verification = verification().withRequest(request()).withTimes(exactly(0));
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), Charsets.UTF_8)).getBodyAsString();
String result = sendRequest(request().withMethod("PUT").withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), StandardCharsets.UTF_8)).getBodyAsString();

if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
Expand Down Expand Up @@ -366,7 +366,7 @@ public String retrieveRecordedRequests(HttpRequest httpRequest, Format format) {
.withPath(calculatePath("retrieve"))
.withQueryStringParameter("type", RetrieveType.REQUESTS.name())
.withQueryStringParameter("format", format.name())
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8)
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8)
);
return httpResponse.getBodyAsString();
}
Expand Down Expand Up @@ -400,7 +400,7 @@ public String retrieveRecordedExpectations(HttpRequest httpRequest, Format forma
.withPath(calculatePath("retrieve"))
.withQueryStringParameter("type", RetrieveType.RECORDED_EXPECTATIONS.name())
.withQueryStringParameter("format", format.name())
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8)
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8)
);
return httpResponse.getBodyAsString();
}
Expand All @@ -417,7 +417,7 @@ public String retrieveLogMessages(HttpRequest httpRequest) {
.withMethod("PUT")
.withPath(calculatePath("retrieve"))
.withQueryStringParameter("type", RetrieveType.LOGS.name())
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8)
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8)
);
return httpResponse.getBodyAsString();
}
Expand Down Expand Up @@ -511,7 +511,7 @@ public ForwardChainExpectation when(HttpRequest httpRequest, Times times, TimeTo
}

void sendExpectation(Expectation expectation) {
HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", Charsets.UTF_8));
HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", StandardCharsets.UTF_8));
if (httpResponse != null && httpResponse.getStatusCode() != 201) {
throw new ClientException(formatLogMessage("error:{}" + NEW_LINE + "while submitted expectation:{}", httpResponse.getBody(), expectation));
}
Expand Down Expand Up @@ -546,7 +546,7 @@ public String retrieveActiveExpectations(HttpRequest httpRequest, Format format)
.withPath(calculatePath("retrieve"))
.withQueryStringParameter("type", RetrieveType.ACTIVE_EXPECTATIONS.name())
.withQueryStringParameter("format", format.name())
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8)
.withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8)
);
return httpResponse.getBodyAsString();
}
Expand Down
Expand Up @@ -17,7 +17,7 @@

import java.util.Arrays;

import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsCollectionContaining.hasItems;
Expand Down
@@ -1,6 +1,5 @@
package org.mockserver.client;

import com.google.common.base.Charsets;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -25,9 +24,10 @@
import org.mockserver.verify.VerificationSequence;
import org.mockserver.verify.VerificationTimes;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;
import static io.netty.handler.codec.http.HttpHeaderNames.HOST;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
Expand Down Expand Up @@ -911,7 +911,7 @@ public void shouldSendClearRequest() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/clear")
.withBody(someRequestMatcher.toString(), Charsets.UTF_8),
.withBody(someRequestMatcher.toString(), StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand All @@ -935,7 +935,7 @@ public void shouldSendClearRequestWithType() {
.withMethod("PUT")
.withPath("/clear")
.withQueryStringParameter("type", "log")
.withBody(someRequestMatcher.toString(), Charsets.UTF_8),
.withBody(someRequestMatcher.toString(), StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand All @@ -953,7 +953,7 @@ public void shouldSendClearRequestForNullRequest() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/clear")
.withBody("", Charsets.UTF_8),
.withBody("", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -985,7 +985,7 @@ public void shouldRetrieveRequests() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.REQUESTS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody(someRequestMatcher.toString(), Charsets.UTF_8),
.withBody(someRequestMatcher.toString(), StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS);
verify(mockHttpRequestSerializer).deserializeArray("body");
Expand All @@ -1009,7 +1009,7 @@ public void shouldRetrieveRequestsWithNullRequest() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.REQUESTS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody("", Charsets.UTF_8),
.withBody("", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1042,7 +1042,7 @@ public void shouldRetrieveActiveExpectations() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.ACTIVE_EXPECTATIONS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody(someRequestMatcher.toString(), Charsets.UTF_8),
.withBody(someRequestMatcher.toString(), StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand All @@ -1067,7 +1067,7 @@ public void shouldRetrieveActiveExpectationsWithNullRequest() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.ACTIVE_EXPECTATIONS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody("", Charsets.UTF_8),
.withBody("", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public void shouldRetrieveRecordedExpectations() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.RECORDED_EXPECTATIONS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody(someRequestMatcher.toString(), Charsets.UTF_8),
.withBody(someRequestMatcher.toString(), StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand All @@ -1125,7 +1125,7 @@ public void shouldRetrieveExpectationsWithNullRequest() {
.withPath("/retrieve")
.withQueryStringParameter("type", RetrieveType.RECORDED_EXPECTATIONS.name())
.withQueryStringParameter("format", Format.JSON.name())
.withBody("", Charsets.UTF_8),
.withBody("", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1153,7 +1153,7 @@ public void shouldVerifyDoesNotMatchSingleRequestNoVerificationTimes() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/verifySequence")
.withBody("verification_json", Charsets.UTF_8),
.withBody("verification_json", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1182,7 +1182,7 @@ public void shouldVerifyDoesNotMatchMultipleRequestsNoVerificationTimes() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/verifySequence")
.withBody("verification_json", Charsets.UTF_8),
.withBody("verification_json", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1214,7 +1214,7 @@ public void shouldVerifyDoesMatchSingleRequestNoVerificationTimes() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/verifySequence")
.withBody("verification_json", Charsets.UTF_8),
.withBody("verification_json", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down Expand Up @@ -1244,7 +1244,7 @@ public void shouldVerifyDoesMatchSingleRequestOnce() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/verify")
.withBody("verification_json", Charsets.UTF_8),
.withBody("verification_json", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand All @@ -1271,7 +1271,7 @@ public void shouldVerifyDoesNotMatchSingleRequest() {
.withHeader(HOST.toString(), "localhost:" + 1080)
.withMethod("PUT")
.withPath("/verify")
.withBody("verification_json", Charsets.UTF_8),
.withBody("verification_json", StandardCharsets.UTF_8),
20000,
TimeUnit.MILLISECONDS
);
Expand Down
Expand Up @@ -4,7 +4,7 @@

import javax.xml.bind.DatatypeConverter;

import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;

/**
* @author jamesdbloom
Expand Down
@@ -1,9 +1,9 @@
package org.mockserver.file;

import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
* @author jamesdbloom
Expand All @@ -12,7 +12,7 @@ public class FileReader {

public static String readFileFromClassPathOrPath(String filePath) {
try {
return IOUtils.toString(openStreamToFileFromClassPathOrPath(filePath), Charsets.UTF_8.name());
return IOUtils.toString(openStreamToFileFromClassPathOrPath(filePath), StandardCharsets.UTF_8.name());
} catch (IOException ioe) {
throw new RuntimeException("Exception while loading \"" + filePath + "\"", ioe);
}
Expand Down
@@ -1,6 +1,5 @@
package org.mockserver.logging;

import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelDuplexHandler;
Expand All @@ -12,6 +11,7 @@
import org.slf4j.LoggerFactory;

import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;

import static org.mockserver.character.Character.NEW_LINE;

Expand Down Expand Up @@ -220,7 +220,7 @@ private String formatByteBuf(String eventName, ByteBuf buf) {
if (relIdxMod16 == 15) {
dump.append(" |");
if (i > 15 && buf.readableBytes() > i) {
dump.append(buf.toString(i - 15, 16, Charsets.UTF_8).replaceAll("" + NEW_LINE, "/").replaceAll("\r", "/"));
dump.append(buf.toString(i - 15, 16, StandardCharsets.UTF_8).replaceAll("" + NEW_LINE, "/").replaceAll("\r", "/"));
} else {
for (int j = i - 15; j <= i; j++) {
dump.append(BYTE2CHAR[buf.getUnsignedByte(j)]);
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import org.mockserver.client.serialization.ObjectMapperFactory;
import org.mockserver.client.serialization.model.*;
Expand All @@ -13,6 +12,8 @@
import static org.mockserver.character.Character.NEW_LINE;
import static org.mockserver.model.NottableString.string;

import java.nio.charset.StandardCharsets;

/**
* @author jamesdbloom
*/
Expand Down Expand Up @@ -219,7 +220,7 @@ private boolean matches(HttpRequest context, HttpRequest request, boolean logMat

private boolean bodyMatches(HttpRequest context, HttpRequest request) {
boolean bodyMatches = true;
String bodyAsString = request.getBody() != null ? new String(request.getBody().getRawBytes(), request.getBody().getCharset(Charsets.UTF_8)) : "";
String bodyAsString = request.getBody() != null ? new String(request.getBody().getRawBytes(), request.getBody().getCharset(StandardCharsets.UTF_8)) : "";
if (!bodyAsString.isEmpty()) {
if (bodyMatcher instanceof BinaryMatcher) {
bodyMatches = matches(context, bodyMatcher, request.getBodyAsRawBytes());
Expand Down
Expand Up @@ -4,7 +4,7 @@

import java.nio.charset.Charset;

import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;

/**
* @author jamesdbloom
Expand Down
@@ -1,10 +1,10 @@
package org.mockserver.model;

import com.google.common.base.Charsets;
import com.google.common.net.MediaType;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ public String toString() {
body.append(parameter.getName().getValue());
body.append('=');
try {
body.append(URLEncoder.encode(value, Charsets.UTF_8.name()));
body.append(URLEncoder.encode(value, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException("UnsupportedEncodingException while encoding body parameters for " + parameters, uee);
}
Expand Down

0 comments on commit 3b543ec

Please sign in to comment.