From 3b543ec96ea2001af84a0d294d4c23657670a2fe Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 1 Feb 2018 01:37:03 -0700 Subject: [PATCH] Replace Guava's Charset with JDK builtin StandardCharsets. --- .../mockserver/client/MockServerClient.java | 24 +++++----- .../MockServerClientIntegrationTest.java | 2 +- .../client/MockServerClientTest.java | 32 ++++++------- .../client/serialization/Base64Converter.java | 2 +- .../java/org/mockserver/file/FileReader.java | 4 +- .../mockserver/logging/LoggingHandler.java | 4 +- .../matchers/HttpRequestMatcher.java | 5 +- .../main/java/org/mockserver/model/Body.java | 2 +- .../org/mockserver/model/ParameterBody.java | 4 +- .../org/mockserver/streams/IOStreamUtils.java | 5 +- .../java/org/mockserver/url/URLEncoder.java | 7 +-- ...kServerRequestEncoderBasicMappingTest.java | 10 ++-- ...ckServerRequestEncoderContentTypeTest.java | 36 +++++++------- .../codec/MockServerResponseDecoderTest.java | 8 ++-- .../serialization/Base64ConverterTest.java | 2 +- .../ExpectationSerializerIntegrationTest.java | 2 +- .../ExpectationWithErrorSerializerTest.java | 2 +- .../body/BodyDTODeserializerTest.java | 12 ++--- .../java/ExpectationToJavaSerializerTest.java | 2 +- .../java/HttpErrorToJavaSerializerTest.java | 2 +- .../java/HttpRequestToJavaSerializerTest.java | 2 +- .../HttpResponseToJavaSerializerTest.java | 2 +- .../model/ExpectationDTOTest.java | 2 +- .../serialization/model/HttpErrorDTOTest.java | 2 +- .../serialization/model/JsonBodyDTOTest.java | 8 ++-- .../model/StringBodyDTOTest.java | 13 ++--- .../body/BinaryBodyDTOSerializerTest.java | 4 +- .../body/BinaryBodySerializerTest.java | 6 +-- .../body/JsonBodyDTOSerializerTest.java | 7 +-- .../body/JsonBodySerializerTest.java | 7 +-- .../body/StringBodyDTOSerializerTest.java | 1 - .../body/StringBodySerializerTest.java | 7 +-- .../body/XmlBodySerializerTest.java | 7 +-- .../mappers/ContentTypeMapperTest.java | 8 ++-- ...RequestToMockServerRequestDecoderTest.java | 2 +- ...ServletResponseEncoderContentTypeTest.java | 4 +- .../matchers/BinaryMatcherTest.java | 2 +- .../matchers/HttpRequestMatcherTest.java | 11 +++-- .../org/mockserver/model/BinaryBodyTest.java | 15 +++--- .../org/mockserver/model/HttpErrorTest.java | 2 +- .../mockserver/model/HttpResponseTest.java | 2 +- .../org/mockserver/model/JsonBodyTest.java | 13 ++--- .../org/mockserver/model/RegexBodyTest.java | 7 +-- .../org/mockserver/model/StringBodyTest.java | 48 +++++++++---------- .../org/mockserver/model/XmlBodyTest.java | 30 ++++++------ .../org/mockserver/model/XpathBodyTest.java | 7 +-- .../codec/MockServerRequestDecoderTest.java | 22 ++++----- ...ServerResponseEncoderBasicMappingTest.java | 2 +- ...erverResponseEncoderContentLengthTest.java | 2 +- ...kServerResponseEncoderContentTypeTest.java | 36 +++++++------- .../mockserver/streams/IOStreamUtilsTest.java | 1 - ...maHttpRequestValidatorIntegrationTest.java | 2 +- .../mockserver/CallbackActionExamples.java | 2 +- .../mockserver/RequestMatcherExamples.java | 4 +- .../mockserver/ResponseActionExamples.java | 6 +-- .../BookServiceApacheHttpClient.java | 5 +- ...cannedTestExpectationResponseCallback.java | 2 +- .../AbstractClientProxyIntegrationTest.java | 10 ++-- ...tractClientSecureProxyIntegrationTest.java | 18 +++---- ...bstractExtendedMockingIntegrationTest.java | 48 +++++++++---------- ...ctExtendedNettyMockingIntegrationTest.java | 24 +++++----- ...ttyPortForwardingProxyIntegrationTest.java | 10 ++-- ...tForwardingSecureProxyIntegrationTest.java | 10 ++-- .../NettyHttpProxySOCKSIntegrationTest.java | 10 ++-- .../DirectProxyUnificationHandlerTest.java | 2 +- ...yUnificationInitializerSOCKSErrorTest.java | 2 +- .../HttpProxyUnificationInitializerTest.java | 2 +- 67 files changed, 307 insertions(+), 299 deletions(-) diff --git a/mockserver-client-java/src/main/java/org/mockserver/client/MockServerClient.java b/mockserver-client-java/src/main/java/org/mockserver/client/MockServerClient.java index d76a819bc..32499ce6f 100644 --- a/mockserver-client-java/src/main/java/org/mockserver/client/MockServerClient.java +++ b/mockserver-client-java/src/main/java/org/mockserver/client/MockServerClient.java @@ -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; @@ -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; @@ -189,7 +189,7 @@ public boolean isRunning(int attempts, long timeout, TimeUnit timeUnit) { * Bind new ports to listen on */ public List 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(); } @@ -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); } @@ -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); } @@ -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); @@ -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); @@ -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); @@ -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(); } @@ -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(); } @@ -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(); } @@ -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)); } @@ -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(); } diff --git a/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientIntegrationTest.java b/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientIntegrationTest.java index 36f015131..f857d8dee 100644 --- a/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientIntegrationTest.java +++ b/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientIntegrationTest.java @@ -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; diff --git a/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientTest.java b/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientTest.java index ab61f3ccc..4025a8b59 100644 --- a/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientTest.java +++ b/mockserver-client-java/src/test/java/org/mockserver/client/MockServerClientTest.java @@ -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; @@ -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; @@ -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 ); @@ -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 ); @@ -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 ); @@ -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"); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); diff --git a/mockserver-core/src/main/java/org/mockserver/client/serialization/Base64Converter.java b/mockserver-core/src/main/java/org/mockserver/client/serialization/Base64Converter.java index df27bb357..89d6d8a78 100644 --- a/mockserver-core/src/main/java/org/mockserver/client/serialization/Base64Converter.java +++ b/mockserver-core/src/main/java/org/mockserver/client/serialization/Base64Converter.java @@ -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 diff --git a/mockserver-core/src/main/java/org/mockserver/file/FileReader.java b/mockserver-core/src/main/java/org/mockserver/file/FileReader.java index 190719b4d..cae214dc8 100644 --- a/mockserver-core/src/main/java/org/mockserver/file/FileReader.java +++ b/mockserver-core/src/main/java/org/mockserver/file/FileReader.java @@ -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 @@ -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); } diff --git a/mockserver-core/src/main/java/org/mockserver/logging/LoggingHandler.java b/mockserver-core/src/main/java/org/mockserver/logging/LoggingHandler.java index 05c759485..cde3ec47d 100644 --- a/mockserver-core/src/main/java/org/mockserver/logging/LoggingHandler.java +++ b/mockserver-core/src/main/java/org/mockserver/logging/LoggingHandler.java @@ -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; @@ -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; @@ -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)]); diff --git a/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestMatcher.java b/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestMatcher.java index 0517a5535..7ea2a3894 100644 --- a/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestMatcher.java +++ b/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestMatcher.java @@ -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.*; @@ -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 */ @@ -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()); diff --git a/mockserver-core/src/main/java/org/mockserver/model/Body.java b/mockserver-core/src/main/java/org/mockserver/model/Body.java index 7fd676809..fcb732a34 100644 --- a/mockserver-core/src/main/java/org/mockserver/model/Body.java +++ b/mockserver-core/src/main/java/org/mockserver/model/Body.java @@ -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 diff --git a/mockserver-core/src/main/java/org/mockserver/model/ParameterBody.java b/mockserver-core/src/main/java/org/mockserver/model/ParameterBody.java index b21ad5991..99166004a 100644 --- a/mockserver-core/src/main/java/org/mockserver/model/ParameterBody.java +++ b/mockserver-core/src/main/java/org/mockserver/model/ParameterBody.java @@ -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; /** @@ -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); } diff --git a/mockserver-core/src/main/java/org/mockserver/streams/IOStreamUtils.java b/mockserver-core/src/main/java/org/mockserver/streams/IOStreamUtils.java index 4629bc0a6..76f78d38a 100644 --- a/mockserver-core/src/main/java/org/mockserver/streams/IOStreamUtils.java +++ b/mockserver-core/src/main/java/org/mockserver/streams/IOStreamUtils.java @@ -1,6 +1,5 @@ package org.mockserver.streams; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.mockserver.logging.MockServerLogger; @@ -13,7 +12,7 @@ import java.net.Socket; import java.nio.ByteBuffer; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockserver.character.Character.NEW_LINE; /** @@ -48,7 +47,7 @@ public static String readInputStreamToString(Socket socket) throws IOException { public static String readInputStreamToString(ServletRequest request) { try { - return IOUtils.toString(request.getInputStream(), Charsets.UTF_8.name()); + return IOUtils.toString(request.getInputStream(), UTF_8.name()); } catch (IOException ioe) { MOCK_SERVER_LOGGER.error("IOException while reading HttpServletRequest input stream", ioe); throw new RuntimeException("IOException while reading HttpServletRequest input stream", ioe); diff --git a/mockserver-core/src/main/java/org/mockserver/url/URLEncoder.java b/mockserver-core/src/main/java/org/mockserver/url/URLEncoder.java index eaf1a6a2b..bcaaf4787 100644 --- a/mockserver-core/src/main/java/org/mockserver/url/URLEncoder.java +++ b/mockserver-core/src/main/java/org/mockserver/url/URLEncoder.java @@ -1,10 +1,10 @@ package org.mockserver.url; -import com.google.common.base.Charsets; import org.mockserver.logging.MockServerLogger; import java.io.ByteArrayOutputStream; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import static org.slf4j.event.Level.TRACE; @@ -28,7 +28,8 @@ public class URLEncoder { public static String encodeURL(String input) { try { - byte[] sourceBytes = URLDecoder.decode(input, Charsets.UTF_8.name()).getBytes(Charsets.UTF_8); + byte[] sourceBytes = URLDecoder.decode(input, StandardCharsets.UTF_8.name()) + .getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream bos = new ByteArrayOutputStream(sourceBytes.length); for (byte aSource : sourceBytes) { int b = aSource; @@ -46,7 +47,7 @@ public static String encodeURL(String input) { bos.write(hex2); } } - return new String(bos.toByteArray(), Charsets.UTF_8); + return new String(bos.toByteArray(), StandardCharsets.UTF_8); } catch (Exception e) { MOCK_SERVER_LOGGER.trace("Exception while decoding or encoding url [" + input + "]", e); return input; diff --git a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderBasicMappingTest.java b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderBasicMappingTest.java index 62d9564dd..c5ea23b45 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderBasicMappingTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderBasicMappingTest.java @@ -1,6 +1,5 @@ package org.mockserver.client.netty.codec; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpHeaders; @@ -11,11 +10,12 @@ import org.mockserver.model.Header; import org.mockserver.model.HttpRequest; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -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.CONTENT_TYPE; import static io.netty.handler.codec.http.HttpHeaderNames.HOST; import static org.hamcrest.MatcherAssert.assertThat; @@ -187,7 +187,7 @@ public void shouldEncodeStringBody() { // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_8), is("somebody")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_8), is("somebody")); assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), nullValue()); } @@ -201,7 +201,7 @@ public void shouldEncodeStringBodyWithContentType() { // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_8), is("somebody")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_8), is("somebody")); assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), is(MediaType.HTML_UTF_8.toString())); } @@ -243,7 +243,7 @@ public void shouldEncodeNullBody() { // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_8), is("")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_8), is("")); } } diff --git a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderContentTypeTest.java b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderContentTypeTest.java index 8c37ef5d3..744efe019 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderContentTypeTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerRequestEncoderContentTypeTest.java @@ -1,6 +1,5 @@ package org.mockserver.client.netty.codec; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.handler.codec.http.FullHttpRequest; import org.hamcrest.collection.IsEmptyCollection; @@ -10,10 +9,11 @@ import org.mockserver.model.Header; import org.mockserver.model.HttpRequest; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -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.CONTENT_TYPE; import static io.netty.handler.codec.http.HttpHeaderNames.HOST; import static org.hamcrest.MatcherAssert.assertThat; @@ -102,43 +102,43 @@ public void shouldUseDefaultCharsetIfCharsetNotSupported() { @Test public void shouldDecodeBodyWithUTF8ContentType() { // given - httpRequest.withBody("avro işarəsi: \u20AC", Charsets.UTF_8); - httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())); + httpRequest.withBody("avro işarəsi: \u20AC", StandardCharsets.UTF_8); + httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString())); // when new MockServerRequestEncoder().encode(null, httpRequest, output); // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_8), is("avro işarəsi: \u20AC")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_8), is("avro işarəsi: \u20AC")); } @Test public void shouldDecodeBodyWithUTF16ContentType() { // given - httpRequest.withBody("我说中国话", Charsets.UTF_16); - httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + httpRequest.withBody("我说中国话", StandardCharsets.UTF_16); + httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); // when new MockServerRequestEncoder().encode(null, httpRequest, output); // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_16), is("我说中国话")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_16), is("我说中国话")); } @Test public void shouldEncodeStringBodyWithCharset() { // given - httpRequest.withBody("我说中国话", Charsets.UTF_16); + httpRequest.withBody("我说中国话", StandardCharsets.UTF_16); // when new MockServerRequestEncoder().encode(null, httpRequest, output); // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_16), is("我说中国话")); - assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), is(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_16), is("我说中国话")); + assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), is(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -151,36 +151,36 @@ public void shouldEncodeUTF8JsonBodyWithContentType() { // then FullHttpRequest fullHttpResponse = (FullHttpRequest) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); assertThat(fullHttpResponse.headers().get(CONTENT_TYPE), is(MediaType.JSON_UTF_8.toString())); } @Test public void shouldEncodeUTF8JsonBodyWithCharset() { // given - httpRequest.withBody(json("{ \"some_field\": \"我说中国话\" }", Charsets.UTF_8)); + httpRequest.withBody(json("{ \"some_field\": \"我说中国话\" }", StandardCharsets.UTF_8)); // when new MockServerRequestEncoder().encode(null, httpRequest, output); // then FullHttpRequest fullHttpResponse = (FullHttpRequest) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); assertThat(fullHttpResponse.headers().get(CONTENT_TYPE), is(MediaType.JSON_UTF_8.toString())); } @Test public void shouldPreferStringBodyCharacterSet() { // given - httpRequest.withBody("avro işarəsi: \u20AC", Charsets.UTF_16); - httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.US_ASCII).toString())); + httpRequest.withBody("avro işarəsi: \u20AC", StandardCharsets.UTF_16); + httpRequest.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.US_ASCII).toString())); // when new MockServerRequestEncoder().encode(null, httpRequest, output); // then FullHttpRequest fullHttpRequest = (FullHttpRequest) output.get(0); - assertThat(fullHttpRequest.content().toString(Charsets.UTF_16), is("avro işarəsi: \u20AC")); + assertThat(fullHttpRequest.content().toString(StandardCharsets.UTF_16), is("avro işarəsi: \u20AC")); } @Test @@ -222,7 +222,7 @@ public void shouldReturnContentTypeForStringBodyWithContentType() { @Test public void shouldReturnContentTypeForStringBodyWithCharset() { // given - a request & response - httpRequest.withBody(exact("somebody", Charsets.UTF_16)); + httpRequest.withBody(exact("somebody", StandardCharsets.UTF_16)); // when new MockServerRequestEncoder().encode(null, httpRequest, output); diff --git a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerResponseDecoderTest.java b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerResponseDecoderTest.java index 609c6ae20..11cbe5cf5 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerResponseDecoderTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/netty/codec/MockServerResponseDecoderTest.java @@ -1,6 +1,5 @@ package org.mockserver.client.netty.codec; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.*; @@ -12,10 +11,11 @@ import org.mockserver.model.Header; import org.mockserver.model.HttpResponse; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -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.CONTENT_TYPE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -126,8 +126,8 @@ public void shouldDecodeUTF8Body() { @Test public void shouldDecodeUTF16Body() { // given - fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer("我说中国话".getBytes(Charsets.UTF_16))); - fullHttpResponse.headers().add(CONTENT_TYPE, MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()); + fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer("我说中国话".getBytes(StandardCharsets.UTF_16))); + fullHttpResponse.headers().add(CONTENT_TYPE, MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()); // when mockServerResponseDecoder.decode(null, fullHttpResponse, output); diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/Base64ConverterTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/Base64ConverterTest.java index b3727d1c3..aed497547 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/Base64ConverterTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/Base64ConverterTest.java @@ -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; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationSerializerIntegrationTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationSerializerIntegrationTest.java index 7fd8494c9..8f93f1cae 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationSerializerIntegrationTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationSerializerIntegrationTest.java @@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.MICROSECONDS; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationWithErrorSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationWithErrorSerializerTest.java index 5fb56a780..4891737cf 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationWithErrorSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/ExpectationWithErrorSerializerTest.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertThat; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/deserializers/body/BodyDTODeserializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/deserializers/body/BodyDTODeserializerTest.java index 44288ce2d..de1230be4 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/deserializers/body/BodyDTODeserializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/deserializers/body/BodyDTODeserializerTest.java @@ -1,6 +1,5 @@ package org.mockserver.client.serialization.deserializers.body; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.apache.commons.text.StringEscapeUtils; import org.junit.Test; @@ -11,8 +10,9 @@ import javax.xml.bind.DatatypeConverter; import java.io.IOException; +import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockserver.character.Character.NEW_LINE; import static org.mockserver.model.HttpRequest.request; @@ -903,7 +903,7 @@ public void shouldParseJsonWithJsonBodyWithContentType() throws IOException { " \"httpRequest\": {" + NEW_LINE + " \"body\" : {" + NEW_LINE + " \"type\" : \"JSON\"," + NEW_LINE + - " \"charset\" : \"" + Charsets.ISO_8859_1 + "\"," + NEW_LINE + + " \"charset\" : \"" + StandardCharsets.ISO_8859_1 + "\"," + NEW_LINE + " \"json\" : \"{'employees':[{'firstName':'John', 'lastName':'Doe'}]}\"" + NEW_LINE + " }" + NEW_LINE + " }" + NEW_LINE + @@ -916,7 +916,7 @@ public void shouldParseJsonWithJsonBodyWithContentType() throws IOException { assertEquals(new ExpectationDTO() .setHttpRequest( new HttpRequestDTO() - .setBody(new JsonBodyDTO(new JsonBody("{'employees':[{'firstName':'John', 'lastName':'Doe'}]}", MediaType.JSON_UTF_8.withCharset(Charsets.ISO_8859_1), MatchType.ONLY_MATCHING_FIELDS))) + .setBody(new JsonBodyDTO(new JsonBody("{'employees':[{'firstName':'John', 'lastName':'Doe'}]}", MediaType.JSON_UTF_8.withCharset(StandardCharsets.ISO_8859_1), MatchType.ONLY_MATCHING_FIELDS))) ), expectationDTO); } @@ -1277,7 +1277,7 @@ public void shouldParseJsonWithXmlBodyWithCharset() throws IOException { String json = ("{" + NEW_LINE + " \"httpRequest\": {" + NEW_LINE + " \"body\" : {" + NEW_LINE + - " \"charset\" : \"" + Charsets.US_ASCII + "\"," + NEW_LINE + + " \"charset\" : \"" + StandardCharsets.US_ASCII + "\"," + NEW_LINE + " \"xml\" : \"\"" + NEW_LINE + " }" + NEW_LINE + " }" + NEW_LINE + @@ -1290,7 +1290,7 @@ public void shouldParseJsonWithXmlBodyWithCharset() throws IOException { assertEquals(new ExpectationDTO() .setHttpRequest( new HttpRequestDTO() - .setBody(new XmlBodyDTO(new XmlBody("", MediaType.APPLICATION_XML_UTF_8.withCharset(Charsets.US_ASCII)))) + .setBody(new XmlBodyDTO(new XmlBody("", MediaType.APPLICATION_XML_UTF_8.withCharset(StandardCharsets.US_ASCII)))) ), expectationDTO); } diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/ExpectationToJavaSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/ExpectationToJavaSerializerTest.java index fc531403c..1f48712d1 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/ExpectationToJavaSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/ExpectationToJavaSerializerTest.java @@ -10,7 +10,7 @@ import java.util.Arrays; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockserver.character.Character.NEW_LINE; import static org.mockserver.matchers.TimeToLive.unlimited; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpErrorToJavaSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpErrorToJavaSerializerTest.java index 0c403b63c..68985f390 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpErrorToJavaSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpErrorToJavaSerializerTest.java @@ -7,7 +7,7 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockserver.character.Character.NEW_LINE; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpRequestToJavaSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpRequestToJavaSerializerTest.java index b10864022..59f15901e 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpRequestToJavaSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpRequestToJavaSerializerTest.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.util.Arrays; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockserver.character.Character.NEW_LINE; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpResponseToJavaSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpResponseToJavaSerializerTest.java index f879053a7..d1dcd4716 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpResponseToJavaSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/java/HttpResponseToJavaSerializerTest.java @@ -9,7 +9,7 @@ import java.io.IOException; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockserver.character.Character.NEW_LINE; import static org.mockserver.model.BinaryBody.binary; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/ExpectationDTOTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/ExpectationDTOTest.java index d1b67e3c5..9d40e19d2 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/ExpectationDTOTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/ExpectationDTOTest.java @@ -6,7 +6,7 @@ import org.mockserver.mock.Expectation; import org.mockserver.model.*; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/HttpErrorDTOTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/HttpErrorDTOTest.java index 4e831449a..86067adb7 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/HttpErrorDTOTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/HttpErrorDTOTest.java @@ -6,7 +6,7 @@ import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/JsonBodyDTOTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/JsonBodyDTOTest.java index fae8a0aef..dbf5dfcb2 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/JsonBodyDTOTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/JsonBodyDTOTest.java @@ -1,18 +1,18 @@ package org.mockserver.client.serialization.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.model.Body; import org.mockserver.model.JsonBody; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; import static org.mockserver.matchers.MatchType.ONLY_MATCHING_FIELDS; import static org.mockserver.matchers.MatchType.STRICT; - /** * @author jamesdbloom */ @@ -45,7 +45,7 @@ public void shouldReturnValuesSetInConstructorWithMatchType() { @Test public void shouldReturnValuesSetInConstructorWithMatchTypeAndCharset() { // when - JsonBodyDTO jsonBody = new JsonBodyDTO(new JsonBody("some_body", Charsets.UTF_16, STRICT)); + JsonBodyDTO jsonBody = new JsonBodyDTO(new JsonBody("some_body", StandardCharsets.UTF_16, STRICT)); // then assertThat(jsonBody.getJson(), is("some_body")); @@ -93,7 +93,7 @@ public void shouldBuildCorrectObjectWithMatchType() { @Test public void shouldBuildCorrectObjectWithMatchTypeAndCharset() { // when - JsonBody jsonBody = new JsonBodyDTO(new JsonBody("some_body", Charsets.UTF_16, STRICT)).buildObject(); + JsonBody jsonBody = new JsonBodyDTO(new JsonBody("some_body", StandardCharsets.UTF_16, STRICT)).buildObject(); // then assertThat(jsonBody.getValue(), is("some_body")); diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/StringBodyDTOTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/StringBodyDTOTest.java index 4f32739f4..47b1d89f0 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/model/StringBodyDTOTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/model/StringBodyDTOTest.java @@ -1,11 +1,12 @@ package org.mockserver.client.serialization.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.model.Body; import org.mockserver.model.StringBody; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -44,7 +45,7 @@ public void shouldReturnValuesSetInConstructorWithSubString() { @Test public void shouldReturnValuesSetInConstructorWithCharset() { // when - StringBodyDTO stringBody = new StringBodyDTO(new StringBody("some_body", Charsets.UTF_8)); + StringBodyDTO stringBody = new StringBodyDTO(new StringBody("some_body", StandardCharsets.UTF_8)); // then assertThat(stringBody.getString(), is("some_body")); @@ -66,7 +67,7 @@ public void shouldReturnValuesSetInConstructorWithContentType() { @Test public void shouldBuildCorrectObject() { // when - StringBody stringBody = new StringBodyDTO(new StringBody("some_body", true, Charsets.UTF_8)).buildObject(); + StringBody stringBody = new StringBodyDTO(new StringBody("some_body", true, StandardCharsets.UTF_8)).buildObject(); // then assertThat(stringBody.getValue(), is("some_body")); @@ -79,13 +80,13 @@ public void shouldBuildCorrectObject() { public void shouldReturnCorrectObjectFromStaticExactBuilder() { assertThat(exact("some_body"), is(new StringBody("some_body", false))); assertThat(exact("some_body"), is(new StringBody("some_body"))); - assertThat(exact("some_body", Charsets.UTF_16), is(new StringBody("some_body", false, Charsets.UTF_16))); - assertThat(exact("some_body", Charsets.UTF_16), is(new StringBody("some_body", Charsets.UTF_16))); + assertThat(exact("some_body", StandardCharsets.UTF_16), is(new StringBody("some_body", false, StandardCharsets.UTF_16))); + assertThat(exact("some_body", StandardCharsets.UTF_16), is(new StringBody("some_body", StandardCharsets.UTF_16))); } @Test public void shouldReturnCorrectObjectFromStaticSubStringBuilder() { assertThat(subString("some_body"), is(new StringBody("some_body", true))); - assertThat(subString("some_body", Charsets.UTF_16), is(new StringBody("some_body", true, Charsets.UTF_16))); + assertThat(subString("some_body", StandardCharsets.UTF_16), is(new StringBody("some_body", true, StandardCharsets.UTF_16))); } } diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodyDTOSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodyDTOSerializerTest.java index cd317a2bd..85eed2a6d 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodyDTOSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodyDTOSerializerTest.java @@ -8,7 +8,7 @@ import org.mockserver.client.serialization.model.BinaryBodyDTO; import org.mockserver.model.BinaryBody; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -40,4 +40,4 @@ public void shouldSerializeBinaryBodyDTOWithNotWithContentType() throws JsonProc is("{\"not\":true,\"type\":\"BINARY\",\"base64Bytes\":\"" + base64Converter.bytesToBase64String("someBytes".getBytes(UTF_8)) + "\",\"contentType\":\"audio/*\"}")); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodySerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodySerializerTest.java index fbcddf020..5f024066e 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodySerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/BinaryBodySerializerTest.java @@ -1,16 +1,14 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; import org.mockserver.model.BinaryBody; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockserver.model.Not.not; public class BinaryBodySerializerTest { @@ -25,4 +23,4 @@ public void shouldSerializeBinaryBodyWithContentType() throws JsonProcessingExce assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new BinaryBody("some_bytes".getBytes(UTF_8), MediaType.APPLICATION_BINARY)), is("{\"contentType\":\"application/binary\",\"type\":\"BINARY\",\"base64Bytes\":\"c29tZV9ieXRlcw==\"}")); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodyDTOSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodyDTOSerializerTest.java index 388f5f63b..172a75699 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodyDTOSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodyDTOSerializerTest.java @@ -1,7 +1,6 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; @@ -9,6 +8,8 @@ import org.mockserver.matchers.MatchType; import org.mockserver.model.JsonBody; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -34,7 +35,7 @@ public void shouldSerializeJsonBodyWithNoneDefaultMatchType() throws JsonProcess @Test public void shouldSerializeJsonBodyWithNoneDefaultMatchTypeAndCharset() throws JsonProcessingException { - assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new JsonBodyDTO(new JsonBody("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", Charsets.UTF_16, MatchType.STRICT))), + assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new JsonBodyDTO(new JsonBody("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", StandardCharsets.UTF_16, MatchType.STRICT))), is("{\"contentType\":\"application/json; charset=utf-16\",\"type\":\"JSON\",\"json\":\"{fieldOne: \\\"valueOne\\\", \\\"fieldTwo\\\": \\\"valueTwo\\\"}\",\"matchType\":\"STRICT\"}")); } @@ -49,4 +50,4 @@ public void shouldSerializeJsonBodyDTOWithNot() throws JsonProcessingException { assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new JsonBodyDTO(new JsonBody("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", MatchType.STRICT), true)), is("{\"not\":true,\"type\":\"JSON\",\"json\":\"{fieldOne: \\\"valueOne\\\", \\\"fieldTwo\\\": \\\"valueTwo\\\"}\",\"matchType\":\"STRICT\"}")); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodySerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodySerializerTest.java index efa406f71..08326b132 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodySerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/JsonBodySerializerTest.java @@ -1,12 +1,13 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; import org.mockserver.matchers.MatchType; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockserver.model.JsonBody.json; @@ -61,7 +62,7 @@ public void shouldSerializeJsonBodyWithMatchType() throws JsonProcessingExceptio @Test public void shouldSerializeJsonBodyWithNoneDefaultMatchTypeAndCharset() throws JsonProcessingException { - assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(json("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", Charsets.UTF_16, MatchType.STRICT)), + assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(json("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", StandardCharsets.UTF_16, MatchType.STRICT)), is("{\"contentType\":\"application/json; charset=utf-16\",\"type\":\"JSON\",\"json\":\"{fieldOne: \\\"valueOne\\\", \\\"fieldTwo\\\": \\\"valueTwo\\\"}\",\"matchType\":\"STRICT\"}")); } @@ -76,4 +77,4 @@ public void shouldSerializeJsonBodyWithMatchTypeWithNot() throws JsonProcessingE assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(json("{fieldOne: \"valueOne\", \"fieldTwo\": \"valueTwo\"}", MatchType.STRICT))), is("{\"not\":true,\"type\":\"JSON\",\"json\":\"{fieldOne: \\\"valueOne\\\", \\\"fieldTwo\\\": \\\"valueTwo\\\"}\",\"matchType\":\"STRICT\"}")); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodyDTOSerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodyDTOSerializerTest.java index f4764ca99..61a789a4a 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodyDTOSerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodyDTOSerializerTest.java @@ -1,7 +1,6 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodySerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodySerializerTest.java index 4718f77da..7011bb912 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodySerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/StringBodySerializerTest.java @@ -1,13 +1,14 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; import org.mockserver.client.serialization.model.StringBodyDTO; import org.mockserver.model.StringBody; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockserver.model.Not.not; @@ -30,7 +31,7 @@ public void shouldSerializeStringBodyDTOWithSubString() throws JsonProcessingExc @Test public void shouldSerializeStringBodyWithCharset() throws JsonProcessingException { - assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new StringBody("string_body", Charsets.UTF_16)), + assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(new StringBody("string_body", StandardCharsets.UTF_16)), is("{\"type\":\"STRING\",\"string\":\"string_body\",\"contentType\":\"text/plain; charset=utf-16\"}")); } @@ -48,7 +49,7 @@ public void shouldSerializeStringBodyWithNot() throws JsonProcessingException { @Test public void shouldSerializeStringBodyWithCharsetAndNot() throws JsonProcessingException { - assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(new StringBody("string_body", Charsets.UTF_16))), + assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(new StringBody("string_body", StandardCharsets.UTF_16))), is("{\"not\":true,\"type\":\"STRING\",\"string\":\"string_body\",\"contentType\":\"text/plain; charset=utf-16\"}")); } diff --git a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/XmlBodySerializerTest.java b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/XmlBodySerializerTest.java index ddce16936..b8457d6c1 100644 --- a/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/XmlBodySerializerTest.java +++ b/mockserver-core/src/test/java/org/mockserver/client/serialization/serializers/body/XmlBodySerializerTest.java @@ -1,7 +1,6 @@ package org.mockserver.client.serialization.serializers.body; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.ObjectMapperFactory; @@ -9,6 +8,8 @@ import org.mockserver.model.JsonBody; import org.mockserver.model.XmlBody; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockserver.model.Not.not; @@ -35,7 +36,7 @@ public void shouldSerializeXmlBodyWithContentType() throws JsonProcessingExcepti @Test public void shouldSerializeXmlBodyWithCharsetAndNot() throws JsonProcessingException { - assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(new XmlBody("", Charsets.UTF_16))), + assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(new XmlBody("", StandardCharsets.UTF_16))), is("{\"not\":true,\"contentType\":\"application/xml; charset=utf-16\",\"type\":\"XML\",\"xml\":\"\"}")); } @@ -44,4 +45,4 @@ public void shouldSerializeXmlBodyWithContentTypeAndNot() throws JsonProcessingE assertThat(ObjectMapperFactory.createObjectMapper().writeValueAsString(not(new XmlBody("", MediaType.ATOM_UTF_8))), is("{\"not\":true,\"contentType\":\"application/atom+xml; charset=utf-8\",\"type\":\"XML\",\"xml\":\"\"}")); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/mappers/ContentTypeMapperTest.java b/mockserver-core/src/test/java/org/mockserver/mappers/ContentTypeMapperTest.java index 61c50471d..6f3450e0c 100644 --- a/mockserver-core/src/test/java/org/mockserver/mappers/ContentTypeMapperTest.java +++ b/mockserver-core/src/test/java/org/mockserver/mappers/ContentTypeMapperTest.java @@ -1,6 +1,5 @@ package org.mockserver.mappers; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMessage; @@ -9,6 +8,7 @@ import javax.servlet.http.HttpServletRequest; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -124,10 +124,10 @@ public void shouldDefaultToNotBinary() { @Test public void shouldDetermineCharsetFromResponseContentType() { // when - Charset charset = ContentTypeMapper.getCharsetFromContentTypeHeader(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()); + Charset charset = ContentTypeMapper.getCharsetFromContentTypeHeader(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()); // then - assertThat(charset, is(Charsets.UTF_16)); + assertThat(charset, is(StandardCharsets.UTF_16)); } @Test @@ -164,4 +164,4 @@ public void shouldDetermineCharsetWhenNoContentTypeHeader() { assertThat(charset, is(ContentTypeMapper.DEFAULT_HTTP_CHARACTER_SET)); } -} \ No newline at end of file +} diff --git a/mockserver-core/src/test/java/org/mockserver/mappers/HttpServletRequestToMockServerRequestDecoderTest.java b/mockserver-core/src/test/java/org/mockserver/mappers/HttpServletRequestToMockServerRequestDecoderTest.java index 6d461b1ab..2da4f9f0c 100644 --- a/mockserver-core/src/test/java/org/mockserver/mappers/HttpServletRequestToMockServerRequestDecoderTest.java +++ b/mockserver-core/src/test/java/org/mockserver/mappers/HttpServletRequestToMockServerRequestDecoderTest.java @@ -10,7 +10,7 @@ import java.util.Arrays; import java.util.Enumeration; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/mockserver-core/src/test/java/org/mockserver/mappers/MockServerResponseToHttpServletResponseEncoderContentTypeTest.java b/mockserver-core/src/test/java/org/mockserver/mappers/MockServerResponseToHttpServletResponseEncoderContentTypeTest.java index 4d5c99317..57c6a17da 100644 --- a/mockserver-core/src/test/java/org/mockserver/mappers/MockServerResponseToHttpServletResponseEncoderContentTypeTest.java +++ b/mockserver-core/src/test/java/org/mockserver/mappers/MockServerResponseToHttpServletResponseEncoderContentTypeTest.java @@ -1,6 +1,5 @@ package org.mockserver.mappers; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.model.Cookie; @@ -13,6 +12,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import static org.hamcrest.CoreMatchers.nullValue; @@ -51,7 +51,7 @@ public void shouldReturnNoDefaultContentTypeWhenNoBodySpecified() { @Test public void shouldReturnContentTypeForStringBodyWithCharset() { // given - HttpResponse httpResponse = response().withBody(exact("somebody", Charsets.US_ASCII)); + HttpResponse httpResponse = response().withBody(exact("somebody", StandardCharsets.US_ASCII)); MockHttpServletResponse httpServletResponse = new MockHttpServletResponse(); // when diff --git a/mockserver-core/src/test/java/org/mockserver/matchers/BinaryMatcherTest.java b/mockserver-core/src/test/java/org/mockserver/matchers/BinaryMatcherTest.java index 8e37117ea..2bff2121e 100644 --- a/mockserver-core/src/test/java/org/mockserver/matchers/BinaryMatcherTest.java +++ b/mockserver-core/src/test/java/org/mockserver/matchers/BinaryMatcherTest.java @@ -3,7 +3,7 @@ import org.junit.Test; import org.mockserver.logging.MockServerLogger; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockserver.matchers.NotMatcher.not; diff --git a/mockserver-core/src/test/java/org/mockserver/matchers/HttpRequestMatcherTest.java b/mockserver-core/src/test/java/org/mockserver/matchers/HttpRequestMatcherTest.java index 685e366f5..51e9000b2 100644 --- a/mockserver-core/src/test/java/org/mockserver/matchers/HttpRequestMatcherTest.java +++ b/mockserver-core/src/test/java/org/mockserver/matchers/HttpRequestMatcherTest.java @@ -1,6 +1,5 @@ package org.mockserver.matchers; -import com.google.common.base.Charsets; import org.junit.Test; import org.mockserver.client.serialization.model.*; import org.mockserver.logging.MockServerLogger; @@ -8,7 +7,9 @@ import org.mockserver.model.*; import org.slf4j.LoggerFactory; -import static com.google.common.base.Charsets.UTF_8; +import java.nio.charset.StandardCharsets; + +import static java.nio.charset.StandardCharsets.UTF_8; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -371,7 +372,7 @@ public void jsonBodyThatIsNotValidDTODoesNotThrowException() { @Test public void matchesMatchingBodyWithCharset() { - assertTrue(new HttpRequestMatcher(new HttpRequest().withBody(new StringBody("我说中国话", Charsets.UTF_16)), mockServerLogger).matches(null, new HttpRequest().withBody("我说中国话", Charsets.UTF_16))); + assertTrue(new HttpRequestMatcher(new HttpRequest().withBody(new StringBody("我说中国话", StandardCharsets.UTF_16)), mockServerLogger).matches(null, new HttpRequest().withBody("我说中国话", StandardCharsets.UTF_16))); } @Test @@ -706,12 +707,12 @@ public void matchesMatchingJSONBodyWithCharset() { assertTrue( new HttpRequestMatcher( new HttpRequest() - .withBody(json("{ \"some_field\": \"我说中国话\" }", Charsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), + .withBody(json("{ \"some_field\": \"我说中国话\" }", StandardCharsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), mockServerLogger ) .matches( null, new HttpRequest() - .withBody(matched, Charsets.UTF_16) + .withBody(matched, StandardCharsets.UTF_16) .withMethod("PUT") ) ); diff --git a/mockserver-core/src/test/java/org/mockserver/model/BinaryBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/BinaryBodyTest.java index ba4948ba4..574278c0c 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/BinaryBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/BinaryBodyTest.java @@ -1,13 +1,14 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.Base64Converter; +import java.nio.charset.StandardCharsets; + import javax.xml.bind.DatatypeConverter; -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.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -47,7 +48,7 @@ public void shouldReturnValuesSetInConstructor() { assertThat(binaryBody.getValue(), is(body)); assertThat(binaryBody.getType(), is(Body.Type.BINARY)); assertThat(binaryBody.getCharset(null), nullValue()); - assertThat(binaryBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(binaryBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(binaryBody.getContentType(), nullValue()); } @@ -63,7 +64,7 @@ public void shouldReturnValueSetInStaticConstructor() { assertThat(binaryBody.getValue(), is(body)); assertThat(binaryBody.getType(), is(Body.Type.BINARY)); assertThat(binaryBody.getCharset(null), nullValue()); - assertThat(binaryBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(binaryBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(binaryBody.getContentType(), nullValue()); } @@ -78,8 +79,8 @@ public void shouldReturnValueSetInStaticConstructorWithCharsetAndMediaType() { // then assertThat(binaryBody.getValue(), is(body)); assertThat(binaryBody.getType(), is(Body.Type.BINARY)); - assertThat(binaryBody.getCharset(null), is(Charsets.UTF_8)); - assertThat(binaryBody.getCharset(Charsets.UTF_16), is(Charsets.UTF_8)); + assertThat(binaryBody.getCharset(null), is(StandardCharsets.UTF_8)); + assertThat(binaryBody.getCharset(StandardCharsets.UTF_16), is(StandardCharsets.UTF_8)); assertThat(binaryBody.getContentType(), is(MediaType.PLAIN_TEXT_UTF_8.toString())); } @@ -95,7 +96,7 @@ public void shouldReturnValueSetInStaticConstructorWithNullMediaType() { assertThat(binaryBody.getValue(), is(body)); assertThat(binaryBody.getType(), is(Body.Type.BINARY)); assertThat(binaryBody.getCharset(null), nullValue()); - assertThat(binaryBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(binaryBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(binaryBody.getContentType(), nullValue()); } diff --git a/mockserver-core/src/test/java/org/mockserver/model/HttpErrorTest.java b/mockserver-core/src/test/java/org/mockserver/model/HttpErrorTest.java index 9ab7f43ee..68d985684 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/HttpErrorTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/HttpErrorTest.java @@ -5,7 +5,7 @@ import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.*; import static org.mockserver.character.Character.NEW_LINE; import static org.mockserver.model.HttpError.error; diff --git a/mockserver-core/src/test/java/org/mockserver/model/HttpResponseTest.java b/mockserver-core/src/test/java/org/mockserver/model/HttpResponseTest.java index 706a257f6..48e90a3c3 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/HttpResponseTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/HttpResponseTest.java @@ -6,7 +6,7 @@ import java.util.Arrays; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.SECONDS; import static junit.framework.TestCase.*; import static org.hamcrest.CoreMatchers.not; diff --git a/mockserver-core/src/test/java/org/mockserver/model/JsonBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/JsonBodyTest.java index d5f7e32cb..c5d9cd356 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/JsonBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/JsonBodyTest.java @@ -1,10 +1,11 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.matchers.MatchType; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.mockserver.matchers.MatchType.ONLY_MATCHING_FIELDS; @@ -43,7 +44,7 @@ public void shouldReturnValuesSetInConstructorWithMatchType() { @Test public void shouldReturnValuesSetInConstructorWithMatchTypeAndCharset() { // when - JsonBody jsonBody = new JsonBody("some_body", Charsets.UTF_16, MatchType.STRICT); + JsonBody jsonBody = new JsonBody("some_body", StandardCharsets.UTF_16, MatchType.STRICT); // then assertThat(jsonBody.getValue(), is("some_body")); @@ -92,7 +93,7 @@ public void shouldReturnValuesFromStaticBuilderWithMatchType() { @Test public void shouldReturnValuesFromStaticBuilderWithCharsetAndMatchType() { // when - JsonBody jsonBody = json("some_body", Charsets.UTF_16, STRICT); + JsonBody jsonBody = json("some_body", StandardCharsets.UTF_16, STRICT); // then assertThat(jsonBody.getValue(), is("some_body")); @@ -116,7 +117,7 @@ public void shouldReturnValuesFromStaticBuilderWithMediaTypeAndMatchType() { @Test public void shouldReturnValuesFromStaticBuilderWithMatchTypeAndCharset() { // when - JsonBody jsonBody = json("some_body", Charsets.UTF_16, STRICT); + JsonBody jsonBody = json("some_body", StandardCharsets.UTF_16, STRICT); // then assertThat(jsonBody.getValue(), is("some_body")); @@ -152,7 +153,7 @@ public void shouldReturnValuesFromStaticObjectBuilderWithMatchType() { @Test public void shouldReturnValuesFromStaticObjectBuilderWithCharsetAndMatchType() { // when - JsonBody jsonBody = json(new TestObject(), Charsets.UTF_16, STRICT); + JsonBody jsonBody = json(new TestObject(), StandardCharsets.UTF_16, STRICT); // then assertThat(jsonBody.getValue(), is("{\"fieldOne\":\"valueOne\",\"fieldTwo\":\"valueTwo\"}")); @@ -176,7 +177,7 @@ public void shouldReturnValuesFromStaticObjectBuilderWithMediaTypeAndMatchType() @Test public void shouldReturnValuesFromStaticObjectBuilderWithMatchTypeAndCharset() { // when - JsonBody jsonBody = json(new TestObject(), Charsets.UTF_16, STRICT); + JsonBody jsonBody = json(new TestObject(), StandardCharsets.UTF_16, STRICT); // then assertThat(jsonBody.getValue(), is("{\"fieldOne\":\"valueOne\",\"fieldTwo\":\"valueTwo\"}")); diff --git a/mockserver-core/src/test/java/org/mockserver/model/RegexBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/RegexBodyTest.java index 685309c7c..d0599da2e 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/RegexBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/RegexBodyTest.java @@ -1,8 +1,9 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import org.junit.Test; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -22,7 +23,7 @@ public void shouldReturnValuesSetInConstructor() { assertThat(regexBody.getValue(), is("some_body")); assertThat(regexBody.getType(), is(Body.Type.REGEX)); assertThat(regexBody.getContentType(), nullValue()); - assertThat(regexBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(regexBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); } @Test @@ -34,7 +35,7 @@ public void shouldReturnValuesFromStaticBuilder() { assertThat(regexBody.getValue(), is("some_body")); assertThat(regexBody.getType(), is(Body.Type.REGEX)); assertThat(regexBody.getContentType(), nullValue()); - assertThat(regexBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(regexBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); } } diff --git a/mockserver-core/src/test/java/org/mockserver/model/StringBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/StringBodyTest.java index 0c22f2c5b..967b4637d 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/StringBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/StringBodyTest.java @@ -1,11 +1,11 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import org.mockserver.client.serialization.model.StringBodyDTO; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; @@ -36,7 +36,7 @@ public void shouldReturnValuesSetInConstructor() { assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @@ -55,14 +55,14 @@ public void shouldReturnValuesSetInConstructorWithSubString() { @Test public void shouldReturnValuesSetInConstructorWithCharset() { // when - StringBody stringBody = new StringBody("some_body", Charsets.UTF_16); + StringBody stringBody = new StringBody("some_body", StandardCharsets.UTF_16); // then assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.getType(), is(Body.Type.STRING)); - assertThat(stringBody.getCharset(null), is(Charsets.UTF_16)); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_16)); - assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + assertThat(stringBody.getCharset(null), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -75,22 +75,22 @@ public void shouldReturnValueSetInStaticExactConstructor() { assertThat(stringBody.isSubString(), is(false)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @Test public void shouldReturnValueSetInStaticExactConstructorWithCharset() { // when - StringBody stringBody = exact("some_body", Charsets.UTF_16); + StringBody stringBody = exact("some_body", StandardCharsets.UTF_16); // then assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.isSubString(), is(false)); assertThat(stringBody.getType(), is(Body.Type.STRING)); - assertThat(stringBody.getCharset(null), is(Charsets.UTF_16)); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_16)); - assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + assertThat(stringBody.getCharset(null), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -103,7 +103,7 @@ public void shouldReturnValueSetInStaticExactConstructorWithNullCharset() { assertThat(stringBody.isSubString(), is(false)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @@ -116,8 +116,8 @@ public void shouldReturnValueSetInStaticExactConstructorWithContentType() { assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.isSubString(), is(false)); assertThat(stringBody.getType(), is(Body.Type.STRING)); - assertThat(stringBody.getCharset(null), is(Charsets.UTF_8)); - assertThat(stringBody.getCharset(Charsets.UTF_16), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(null), is(StandardCharsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_16), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), is(MediaType.PLAIN_TEXT_UTF_8.toString())); } @@ -131,7 +131,7 @@ public void shouldReturnValueSetInStaticExactConstructorWithNullMediaType() { assertThat(stringBody.isSubString(), is(false)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @@ -145,22 +145,22 @@ public void shouldReturnValueSetInStaticSubStringConstructor() { assertThat(stringBody.isSubString(), is(true)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @Test public void shouldReturnValueSetInStaticSubStringConstructorWithCharset() { // when - StringBody stringBody = subString("some_body", Charsets.UTF_16); + StringBody stringBody = subString("some_body", StandardCharsets.UTF_16); // then assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.isSubString(), is(true)); assertThat(stringBody.getType(), is(Body.Type.STRING)); - assertThat(stringBody.getCharset(null), is(Charsets.UTF_16)); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_16)); - assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + assertThat(stringBody.getCharset(null), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_16)); + assertThat(stringBody.getContentType(), is(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -173,7 +173,7 @@ public void shouldReturnValueSetInStaticSubStringConstructorWithNullCharset() { assertThat(stringBody.isSubString(), is(true)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } @@ -186,8 +186,8 @@ public void shouldReturnValueSetInStaticSubStringConstructorWithContentType() { assertThat(stringBody.getValue(), is("some_body")); assertThat(stringBody.isSubString(), is(true)); assertThat(stringBody.getType(), is(Body.Type.STRING)); - assertThat(stringBody.getCharset(null), is(Charsets.UTF_8)); - assertThat(stringBody.getCharset(Charsets.UTF_16), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(null), is(StandardCharsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_16), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), is(MediaType.PLAIN_TEXT_UTF_8.toString())); } @@ -201,7 +201,7 @@ public void shouldReturnValueSetInStaticSubStringConstructorWithNullMediaType() assertThat(stringBody.isSubString(), is(true)); assertThat(stringBody.getType(), is(Body.Type.STRING)); assertThat(stringBody.getCharset(null), nullValue()); - assertThat(stringBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(stringBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(stringBody.getContentType(), nullValue()); } diff --git a/mockserver-core/src/test/java/org/mockserver/model/XmlBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/XmlBodyTest.java index da1798fbe..3b88ed0d4 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/XmlBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/XmlBodyTest.java @@ -1,10 +1,10 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.junit.Test; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; @@ -33,21 +33,21 @@ public void shouldReturnValuesSetInConstructor() { assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); assertThat(xmlBody.getContentType(), is(XmlBody.DEFAULT_CONTENT_TYPE.toString())); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(xmlBody.getContentType(), is(MediaType.create("application", "xml").toString())); } @Test public void shouldReturnValuesSetInConstructorWithCharset() { // when - XmlBody xmlBody = new XmlBody("some_body", Charsets.UTF_16); + XmlBody xmlBody = new XmlBody("some_body", StandardCharsets.UTF_16); // then assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); - assertThat(xmlBody.getCharset(null), is(Charsets.UTF_16)); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_16)); - assertThat(xmlBody.getContentType(), is(MediaType.APPLICATION_XML_UTF_8.withCharset(Charsets.UTF_16).toString())); + assertThat(xmlBody.getCharset(null), is(StandardCharsets.UTF_16)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_16)); + assertThat(xmlBody.getContentType(), is(MediaType.APPLICATION_XML_UTF_8.withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -59,21 +59,21 @@ public void shouldReturnValueSetInStaticConstructor() { assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); assertThat(xmlBody.getContentType(), is(XmlBody.DEFAULT_CONTENT_TYPE.toString())); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(xmlBody.getContentType(), is(MediaType.create("application", "xml").toString())); } @Test public void shouldReturnValueSetInStaticConstructorWithCharset() { // when - XmlBody xmlBody = xml("some_body", Charsets.UTF_16); + XmlBody xmlBody = xml("some_body", StandardCharsets.UTF_16); // then assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); - assertThat(xmlBody.getCharset(null), is(Charsets.UTF_16)); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_16)); - assertThat(xmlBody.getContentType(), is(MediaType.APPLICATION_XML_UTF_8.withCharset(Charsets.UTF_16).toString())); + assertThat(xmlBody.getCharset(null), is(StandardCharsets.UTF_16)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_16)); + assertThat(xmlBody.getContentType(), is(MediaType.APPLICATION_XML_UTF_8.withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -85,7 +85,7 @@ public void shouldReturnValueSetInStaticConstructorWithNullCharset() { assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); assertThat(xmlBody.getCharset(null), nullValue()); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(xmlBody.getContentType(), nullValue()); } @@ -97,8 +97,8 @@ public void shouldReturnValueSetInStaticConstructorWithContentType() { // then assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); - assertThat(xmlBody.getCharset(null), is(Charsets.UTF_8)); - assertThat(xmlBody.getCharset(Charsets.UTF_16), is(Charsets.UTF_8)); + assertThat(xmlBody.getCharset(null), is(StandardCharsets.UTF_8)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_16), is(StandardCharsets.UTF_8)); assertThat(xmlBody.getContentType(), is(MediaType.PLAIN_TEXT_UTF_8.toString())); } @@ -111,7 +111,7 @@ public void shouldReturnValueSetInStaticConstructorWithNullMediaType() { assertThat(xmlBody.getValue(), is("some_body")); assertThat(xmlBody.getType(), is(Body.Type.XML)); assertThat(xmlBody.getCharset(null), nullValue()); - assertThat(xmlBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xmlBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); assertThat(xmlBody.getContentType(), nullValue()); } diff --git a/mockserver-core/src/test/java/org/mockserver/model/XpathBodyTest.java b/mockserver-core/src/test/java/org/mockserver/model/XpathBodyTest.java index b96b711bf..18d1ecc5d 100644 --- a/mockserver-core/src/test/java/org/mockserver/model/XpathBodyTest.java +++ b/mockserver-core/src/test/java/org/mockserver/model/XpathBodyTest.java @@ -1,8 +1,9 @@ package org.mockserver.model; -import com.google.common.base.Charsets; import org.junit.Test; +import java.nio.charset.StandardCharsets; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -22,7 +23,7 @@ public void shouldReturnValuesSetInConstructor() { assertThat(xPathBody.getValue(), is("some_body")); assertThat(xPathBody.getType(), is(Body.Type.XPATH)); assertThat(xPathBody.getContentType(), nullValue()); - assertThat(xPathBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xPathBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); } @Test @@ -34,7 +35,7 @@ public void shouldReturnValuesFromStaticBuilder() { assertThat(xPathBody.getValue(), is("some_body")); assertThat(xPathBody.getType(), is(Body.Type.XPATH)); assertThat(xPathBody.getContentType(), nullValue()); - assertThat(xPathBody.getCharset(Charsets.UTF_8), is(Charsets.UTF_8)); + assertThat(xPathBody.getCharset(StandardCharsets.UTF_8), is(StandardCharsets.UTF_8)); } } diff --git a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerRequestDecoderTest.java b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerRequestDecoderTest.java index 453c4d847..16087aa61 100644 --- a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerRequestDecoderTest.java +++ b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerRequestDecoderTest.java @@ -1,6 +1,5 @@ package org.mockserver.server.netty.codec; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.*; @@ -14,10 +13,11 @@ import org.mockserver.model.Cookie; import org.mockserver.model.HttpRequest; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -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.CONTENT_TYPE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -173,10 +173,10 @@ public void shouldDecodeCookiesWithEmbeddedEquals() { )); } - /* + /* * Test is significant because popular Java REST library Jersey adds $Version=1 to all cookies - * in line with RFC2965's recommendation (even though RFC2965 is now marked "Obsolete" by - * RFC6265, this is still common and not hard to handle). + * in line with RFC2965's recommendation (even though RFC2965 is now marked "Obsolete" by + * RFC6265, this is still common and not hard to handle). */ @Test public void shouldDecodeCookiesWithRFC2965StyleAttributes() { @@ -193,7 +193,7 @@ public void shouldDecodeCookiesWithRFC2965StyleAttributes() { cookie("Customer", "WILE_E_COYOTE") )); } - + @Test public void shouldDecodeBodyWithContentTypeAndNoCharset() { // given @@ -253,7 +253,7 @@ public void shouldUseDefaultCharsetIfCharsetNotSupported() { @Test public void shouldDecodeBodyWithUTF8ContentType() { // given - fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/uri", Unpooled.wrappedBuffer("avro işarəsi: \u20AC".getBytes(Charsets.UTF_8))); + fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/uri", Unpooled.wrappedBuffer("avro işarəsi: \u20AC".getBytes(StandardCharsets.UTF_8))); fullHttpRequest.headers().add(CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString()); // when @@ -261,21 +261,21 @@ public void shouldDecodeBodyWithUTF8ContentType() { // then Body body = ((HttpRequest) output.get(0)).getBody(); - assertThat(body, Is.is(exact("avro işarəsi: \u20AC", Charsets.UTF_8))); + assertThat(body, Is.is(exact("avro işarəsi: \u20AC", StandardCharsets.UTF_8))); } @Test public void shouldDecodeBodyWithUTF16ContentType() { // given - fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/uri", Unpooled.wrappedBuffer("我说中国话".getBytes(Charsets.UTF_16))); - fullHttpRequest.headers().add(CONTENT_TYPE, MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()); + fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/uri", Unpooled.wrappedBuffer("我说中国话".getBytes(StandardCharsets.UTF_16))); + fullHttpRequest.headers().add(CONTENT_TYPE, MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()); // when mockServerRequestDecoder.decode(null, fullHttpRequest, output); // then Body body = ((HttpRequest) output.get(0)).getBody(); - assertThat(body, Is.is(exact("我说中国话", Charsets.UTF_16))); + assertThat(body, Is.is(exact("我说中国话", StandardCharsets.UTF_16))); } @Test diff --git a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderBasicMappingTest.java b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderBasicMappingTest.java index de33c02af..7d98f812f 100644 --- a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderBasicMappingTest.java +++ b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderBasicMappingTest.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.List; -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.CONTENT_LENGTH; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; diff --git a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentLengthTest.java b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentLengthTest.java index 0a8ccd95e..ad93434f4 100644 --- a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentLengthTest.java +++ b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentLengthTest.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.List; -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.Matchers.containsInAnyOrder; import static org.hamcrest.core.Is.is; diff --git a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentTypeTest.java b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentTypeTest.java index d3a0ef232..5fa54933a 100644 --- a/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentTypeTest.java +++ b/mockserver-core/src/test/java/org/mockserver/server/netty/codec/MockServerResponseEncoderContentTypeTest.java @@ -1,6 +1,5 @@ package org.mockserver.server.netty.codec; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.util.CharsetUtil; @@ -11,10 +10,11 @@ import org.mockserver.model.HttpResponse; import org.mockserver.server.netty.codec.MockServerResponseEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -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.CONTENT_TYPE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; @@ -102,43 +102,43 @@ public void shouldUseDefaultCharsetIfCharsetNotSupported() { @Test public void shouldDecodeBodyWithUTF8ContentType() { // given - httpResponse.withBody("avro işarəsi: \u20AC", Charsets.UTF_8); - httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())); + httpResponse.withBody("avro işarəsi: \u20AC", StandardCharsets.UTF_8); + httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString())); // when new MockServerResponseEncoder().encode(null, httpResponse, output); // then FullHttpResponse fullHttpResponse = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_8), is("avro işarəsi: \u20AC")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_8), is("avro işarəsi: \u20AC")); } @Test public void shouldDecodeBodyWithUTF16ContentType() { // given - httpResponse.withBody("我说中国话", Charsets.UTF_16); - httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + httpResponse.withBody("我说中国话", StandardCharsets.UTF_16); + httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); // when new MockServerResponseEncoder().encode(null, httpResponse, output); // then FullHttpResponse fullHttpResponse = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_16), is("我说中国话")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_16), is("我说中国话")); } @Test public void shouldEncodeStringBodyWithCharset() { // given - httpResponse.withBody("我说中国话", Charsets.UTF_16); + httpResponse.withBody("我说中国话", StandardCharsets.UTF_16); // when new MockServerResponseEncoder().encode(null, httpResponse, output); // then FullHttpResponse fullHttpRequest = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpRequest.content().array(), Charsets.UTF_16), is("我说中国话")); - assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), is(MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())); + assertThat(new String(fullHttpRequest.content().array(), StandardCharsets.UTF_16), is("我说中国话")); + assertThat(fullHttpRequest.headers().get(CONTENT_TYPE), is(MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString())); } @Test @@ -151,36 +151,36 @@ public void shouldEncodeUTF8JsonBodyWithContentType() { // then FullHttpResponse fullHttpResponse = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); assertThat(fullHttpResponse.headers().get(CONTENT_TYPE), is(MediaType.JSON_UTF_8.toString())); } @Test public void shouldEncodeUTF8JsonBodyWithCharset() { // given - httpResponse.withBody(json("{ \"some_field\": \"我说中国话\" }", Charsets.UTF_8)); + httpResponse.withBody(json("{ \"some_field\": \"我说中国话\" }", StandardCharsets.UTF_8)); // when new MockServerResponseEncoder().encode(null, httpResponse, output); // then FullHttpResponse fullHttpResponse = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_8), is("{ \"some_field\": \"我说中国话\" }")); assertThat(fullHttpResponse.headers().get(CONTENT_TYPE), is(MediaType.JSON_UTF_8.toString())); } @Test public void shouldPreferStringBodyCharacterSet() { // given - httpResponse.withBody("avro işarəsi: \u20AC", Charsets.UTF_16); - httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.US_ASCII).toString())); + httpResponse.withBody("avro işarəsi: \u20AC", StandardCharsets.UTF_16); + httpResponse.withHeader(new Header(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.US_ASCII).toString())); // when new MockServerResponseEncoder().encode(null, httpResponse, output); // then FullHttpResponse fullHttpResponse = (FullHttpResponse) output.get(0); - assertThat(new String(fullHttpResponse.content().array(), Charsets.UTF_16), is("avro işarəsi: \u20AC")); + assertThat(new String(fullHttpResponse.content().array(), StandardCharsets.UTF_16), is("avro işarəsi: \u20AC")); } @Test @@ -222,7 +222,7 @@ public void shouldReturnContentTypeForStringBodyWithContentType() { @Test public void shouldReturnContentTypeForStringBodyWithCharset() { // given - a request & response - httpResponse.withBody(exact("somebody", Charsets.UTF_16)); + httpResponse.withBody(exact("somebody", StandardCharsets.UTF_16)); // when new MockServerResponseEncoder().encode(null, httpResponse, output); diff --git a/mockserver-core/src/test/java/org/mockserver/streams/IOStreamUtilsTest.java b/mockserver-core/src/test/java/org/mockserver/streams/IOStreamUtilsTest.java index 3e82f3921..e305164c1 100644 --- a/mockserver-core/src/test/java/org/mockserver/streams/IOStreamUtilsTest.java +++ b/mockserver-core/src/test/java/org/mockserver/streams/IOStreamUtilsTest.java @@ -1,6 +1,5 @@ package org.mockserver.streams; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.junit.Test; diff --git a/mockserver-core/src/test/java/org/mockserver/validator/jsonschema/JsonSchemaHttpRequestValidatorIntegrationTest.java b/mockserver-core/src/test/java/org/mockserver/validator/jsonschema/JsonSchemaHttpRequestValidatorIntegrationTest.java index 021a4adc9..ae906a785 100644 --- a/mockserver-core/src/test/java/org/mockserver/validator/jsonschema/JsonSchemaHttpRequestValidatorIntegrationTest.java +++ b/mockserver-core/src/test/java/org/mockserver/validator/jsonschema/JsonSchemaHttpRequestValidatorIntegrationTest.java @@ -4,7 +4,7 @@ import org.mockserver.client.serialization.HttpRequestSerializer; import org.mockserver.logging.MockServerLogger; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockserver.character.Character.NEW_LINE; diff --git a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/CallbackActionExamples.java b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/CallbackActionExamples.java index 06e4563eb..4a0324f9e 100644 --- a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/CallbackActionExamples.java +++ b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/CallbackActionExamples.java @@ -7,7 +7,7 @@ import org.mockserver.model.HttpResponse; import org.mockserver.model.HttpStatusCode; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockserver.model.Header.header; import static org.mockserver.model.HttpClassCallback.callback; import static org.mockserver.model.HttpRequest.request; diff --git a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/RequestMatcherExamples.java b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/RequestMatcherExamples.java index 71a2dbea7..8a0dc1daf 100644 --- a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/RequestMatcherExamples.java +++ b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/RequestMatcherExamples.java @@ -1,6 +1,5 @@ package org.mockserver.examples.mockserver; -import com.google.common.base.Charsets; import org.mockserver.client.MockServerClient; import org.mockserver.matchers.MatchType; import org.mockserver.matchers.TimeToLive; @@ -8,6 +7,7 @@ import org.mockserver.model.HttpStatusCode; import org.mockserver.model.Not; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import static org.mockserver.model.Cookie.cookie; @@ -282,7 +282,7 @@ public void matchRequestByBodyInUTF16() { new MockServerClient("localhost", 1080) .when( request() - .withBody(exact("我说中国话", Charsets.UTF_16)) + .withBody(exact("我说中国话", StandardCharsets.UTF_16)) ) .respond( response() diff --git a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/ResponseActionExamples.java b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/ResponseActionExamples.java index a276ef935..d9fe42e19 100644 --- a/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/ResponseActionExamples.java +++ b/mockserver-examples/src/main/java/org/mockserver/examples/mockserver/ResponseActionExamples.java @@ -1,6 +1,5 @@ package org.mockserver.examples.mockserver; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.apache.commons.io.IOUtils; import org.mockserver.client.MockServerClient; @@ -9,6 +8,7 @@ import org.mockserver.model.HttpTemplate; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_DISPOSITION; @@ -47,9 +47,9 @@ public void responseLiteralWithUTF16BodyResponse() { response() .withHeader( CONTENT_TYPE.toString(), - MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString() + MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString() ) - .withBody("我说中国话".getBytes(Charsets.UTF_16)) + .withBody("我说中国话".getBytes(StandardCharsets.UTF_16)) ); } diff --git a/mockserver-examples/src/main/java/org/mockserver/examples/proxy/service/apacheclient/BookServiceApacheHttpClient.java b/mockserver-examples/src/main/java/org/mockserver/examples/proxy/service/apacheclient/BookServiceApacheHttpClient.java index 067591672..fb502831d 100644 --- a/mockserver-examples/src/main/java/org/mockserver/examples/proxy/service/apacheclient/BookServiceApacheHttpClient.java +++ b/mockserver-examples/src/main/java/org/mockserver/examples/proxy/service/apacheclient/BookServiceApacheHttpClient.java @@ -1,7 +1,6 @@ package org.mockserver.examples.proxy.service.apacheclient; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Charsets; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -16,6 +15,8 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import java.nio.charset.StandardCharsets; + import javax.annotation.PostConstruct; import javax.annotation.Resource; @@ -57,7 +58,7 @@ public Book[] getAllBooks() { .setPort(port) .setPath("/get_books") .build())); - responseBody = new String(EntityUtils.toByteArray(response.getEntity()), Charsets.UTF_8); + responseBody = new String(EntityUtils.toByteArray(response.getEntity()), StandardCharsets.UTF_8); } catch (Exception e) { throw new RuntimeException("Exception making request to retrieve all books", e); } diff --git a/mockserver-integration-testing/src/main/java/org/mockserver/integration/callback/PrecannedTestExpectationResponseCallback.java b/mockserver-integration-testing/src/main/java/org/mockserver/integration/callback/PrecannedTestExpectationResponseCallback.java index 5bab354c4..3b2faac56 100644 --- a/mockserver-integration-testing/src/main/java/org/mockserver/integration/callback/PrecannedTestExpectationResponseCallback.java +++ b/mockserver-integration-testing/src/main/java/org/mockserver/integration/callback/PrecannedTestExpectationResponseCallback.java @@ -5,7 +5,7 @@ import org.mockserver.model.HttpResponse; import org.mockserver.model.HttpStatusCode; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockserver.model.Header.header; import static org.mockserver.model.HttpResponse.notFoundResponse; import static org.mockserver.model.HttpResponse.response; diff --git a/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientProxyIntegrationTest.java b/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientProxyIntegrationTest.java index 78fe595ad..ee18af1b8 100644 --- a/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientProxyIntegrationTest.java +++ b/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientProxyIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.proxy; -import com.google.common.base.Charsets; import com.google.common.base.Strings; import org.apache.http.Header; import org.apache.http.HttpHost; @@ -30,6 +29,7 @@ import java.io.OutputStream; import java.net.Socket; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import static io.netty.handler.codec.http.HttpHeaderNames.HOST; @@ -112,7 +112,7 @@ public void shouldForwardRequestsUsingSocketDirectly() throws Exception { "x-test: test_headers_only\r" + NEW_LINE + "Connection: keep-alive\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -130,11 +130,11 @@ public void shouldForwardRequestsUsingSocketDirectly() throws Exception { output.write(("" + "GET " + addContextToPath("test_headers_and_body") + " HTTP/1.1\r" + NEW_LINE + "Host: localhost:" + getServerPort() + "\r" + NEW_LINE + - "Content-Length: " + "an_example_body".getBytes(Charsets.UTF_8).length + "\r" + NEW_LINE + + "Content-Length: " + "an_example_body".getBytes(StandardCharsets.UTF_8).length + "\r" + NEW_LINE + "x-test: test_headers_and_body\r" + NEW_LINE + "\r" + NEW_LINE + "an_example_body" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -249,7 +249,7 @@ public void shouldForwardRequestsToUnknownPath() throws Exception { "Host: localhost:" + getServerPort() + "\r" + NEW_LINE + "Connection: close\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then diff --git a/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientSecureProxyIntegrationTest.java b/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientSecureProxyIntegrationTest.java index 165c653cf..2be5b861c 100644 --- a/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientSecureProxyIntegrationTest.java +++ b/mockserver-integration-testing/src/main/java/org/mockserver/integration/proxy/AbstractClientSecureProxyIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.proxy; -import com.google.common.base.Charsets; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -21,6 +20,7 @@ import javax.net.ssl.SSLSocket; import java.io.OutputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; import static org.mockserver.model.HttpRequest.request; @@ -52,7 +52,7 @@ public void shouldConnectToSecurePort() throws Exception { "CONNECT localhost:443 HTTP/1.1\r\n" + "Host: localhost:" + getServerSecurePort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -78,7 +78,7 @@ public void shouldForwardRequestsToSecurePortUsingSocketDirectly() throws Except "CONNECT localhost:443 HTTP/1.1\r\n" + "Host: localhost:" + getServerSecurePort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // - flush CONNECT response @@ -98,7 +98,7 @@ public void shouldForwardRequestsToSecurePortUsingSocketDirectly() throws Except "X-Test: test_headers_only\r\n" + "Connection: keep-alive\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -108,11 +108,11 @@ public void shouldForwardRequestsToSecurePortUsingSocketDirectly() throws Except output.write(("" + "GET /test_headers_and_body HTTP/1.1\r\n" + "Host: localhost:" + getServerSecurePort() + "\r\n" + - "Content-Length: " + "an_example_body".getBytes(Charsets.UTF_8).length + "\r\n" + + "Content-Length: " + "an_example_body".getBytes(StandardCharsets.UTF_8).length + "\r\n" + "X-Test: test_headers_and_body\r\n" + "\r\n" + "an_example_body" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -169,7 +169,7 @@ public void shouldForwardRequestsToSecurePortUsingHttpClientViaHTTP_CONNECT() th // then assertEquals(HttpStatusCode.OK_200.code(), response.getStatusLine().getStatusCode()); - assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), com.google.common.base.Charsets.UTF_8)); + assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), StandardCharsets.UTF_8)); // and getProxyClient().verify( @@ -194,7 +194,7 @@ public void shouldForwardRequestsToSecurePortAndUnknownPath() throws Exception { "CONNECT localhost:443 HTTP/1.1\r\n" + "Host: localhost:" + getServerSecurePort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // - flush CONNECT response @@ -211,7 +211,7 @@ public void shouldForwardRequestsToSecurePortAndUnknownPath() throws Exception { "GET /not_found HTTP/1.1\r\n" + "Host: localhost:" + getServerSecurePort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then diff --git a/mockserver-integration-testing/src/main/java/org/mockserver/integration/server/AbstractExtendedMockingIntegrationTest.java b/mockserver-integration-testing/src/main/java/org/mockserver/integration/server/AbstractExtendedMockingIntegrationTest.java index 9f5dba86f..bd97495f8 100644 --- a/mockserver-integration-testing/src/main/java/org/mockserver/integration/server/AbstractExtendedMockingIntegrationTest.java +++ b/mockserver-integration-testing/src/main/java/org/mockserver/integration/server/AbstractExtendedMockingIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.server; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import com.google.common.util.concurrent.Uninterruptibles; import org.apache.commons.io.IOUtils; @@ -17,6 +16,7 @@ import org.mockserver.verify.VerificationTimes; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.*; @@ -312,26 +312,26 @@ public void shouldReturnResponseWhenTimeToLiveHasNotExpired() { public void shouldReturnMatchRequestWithBodyInUTF16() { // when String body = "我说中国话"; - mockServerClient.when(request().withBody(body, Charsets.UTF_16)).respond(response().withBody(body, Charsets.UTF_8)); + mockServerClient.when(request().withBody(body, StandardCharsets.UTF_16)).respond(response().withBody(body, StandardCharsets.UTF_8)); // then // - in http assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), makeRequest( request() .withPath(calculatePath("")) - .withBody(body, Charsets.UTF_16), + .withBody(body, StandardCharsets.UTF_16), headersToIgnore) ); // - in https assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), @@ -339,7 +339,7 @@ public void shouldReturnMatchRequestWithBodyInUTF16() { request() .withSecure(true) .withPath(calculatePath("")) - .withBody(body, Charsets.UTF_16), + .withBody(body, StandardCharsets.UTF_16), headersToIgnore) ); } @@ -351,25 +351,25 @@ public void shouldReturnMatchRequestWithBodyInUTF8WithContentTypeHeader() { mockServerClient .when( request() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withBody(body) ) .respond( response() - .withBody(body, Charsets.UTF_8) + .withBody(body, StandardCharsets.UTF_8) ); // then // - in http assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), makeRequest( request() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withPath(calculatePath("")) .withBody(body), headersToIgnore) @@ -377,13 +377,13 @@ public void shouldReturnMatchRequestWithBodyInUTF8WithContentTypeHeader() { // - in https assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), makeRequest( request() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withSecure(true) .withPath(calculatePath("")) .withBody(body), @@ -395,13 +395,13 @@ public void shouldReturnMatchRequestWithBodyInUTF8WithContentTypeHeader() { public void shouldReturnResponseWithBodyInUTF16() { // when String body = "我说中国话"; - mockServerClient.when(request()).respond(response().withBody(body, Charsets.UTF_16)); + mockServerClient.when(request()).respond(response().withBody(body, StandardCharsets.UTF_16)); // then // - in http assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), @@ -413,7 +413,7 @@ public void shouldReturnResponseWithBodyInUTF16() { // - in https assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), @@ -435,7 +435,7 @@ public void shouldReturnResponseWithBodyInUTF8WithContentTypeHeader() { ) .respond( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withBody(body) ); @@ -443,7 +443,7 @@ public void shouldReturnResponseWithBodyInUTF8WithContentTypeHeader() { // - in http assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), @@ -455,7 +455,7 @@ public void shouldReturnResponseWithBodyInUTF8WithContentTypeHeader() { // - in https assertEquals( response() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString()) .withStatusCode(OK_200.code()) .withReasonPhrase(OK_200.reasonPhrase()) .withBody(body), @@ -720,7 +720,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithCharsetUTF8() { " \"όνομα\": \"μια πράσινη πόρτα\"," + NEW_LINE + " \"τιμή\": 12.50," + NEW_LINE + " \"ετικέτες\": [\"σπίτι\", \"πράσινος\"]" + NEW_LINE + - "}", Charsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), + "}", StandardCharsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), exactly(2) ) .respond( @@ -747,7 +747,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithCharsetUTF8() { " \"όνομα\": \"μια πράσινη πόρτα\"," + NEW_LINE + " \"τιμή\": 12.50," + NEW_LINE + " \"ετικέτες\": [\"σπίτι\", \"πράσινος\"]" + NEW_LINE + - "}", Charsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), + "}", StandardCharsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), headersToIgnore) ); // - in https @@ -767,7 +767,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithCharsetUTF8() { " \"όνομα\": \"μια πράσινη πόρτα\"," + NEW_LINE + " \"τιμή\": 12.50," + NEW_LINE + " \"ετικέτες\": [\"σπίτι\", \"πράσινος\"]" + NEW_LINE + - "}", Charsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), + "}", StandardCharsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), headersToIgnore) ); } @@ -783,7 +783,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithContentTypeHeader() { " \"όνομα\": \"μια πράσινη πόρτα\"," + NEW_LINE + " \"τιμή\": 12.50," + NEW_LINE + " \"ετικέτες\": [\"σπίτι\", \"πράσινος\"]" + NEW_LINE + - "}", Charsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), + "}", StandardCharsets.UTF_16, MatchType.ONLY_MATCHING_FIELDS)), exactly(2) ) .respond( @@ -802,7 +802,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithContentTypeHeader() { .withBody("some_body"), makeRequest( request() - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()) .withPath(calculatePath("some_path")) .withMethod("POST") .withBody(json("{" + NEW_LINE + @@ -823,7 +823,7 @@ public void shouldReturnResponseByMatchingBodyWithJsonWithContentTypeHeader() { makeRequest( request() .withSecure(true) - .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()) + .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_16).toString()) .withPath(calculatePath("some_path")) .withMethod("POST") .withBody(json("{" + NEW_LINE + diff --git a/mockserver-netty/src/test/java/org/mockserver/integration/mocking/AbstractExtendedNettyMockingIntegrationTest.java b/mockserver-netty/src/test/java/org/mockserver/integration/mocking/AbstractExtendedNettyMockingIntegrationTest.java index 172979c63..ec988b656 100644 --- a/mockserver-netty/src/test/java/org/mockserver/integration/mocking/AbstractExtendedNettyMockingIntegrationTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/integration/mocking/AbstractExtendedNettyMockingIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.mocking; -import com.google.common.base.Charsets; import com.google.common.net.MediaType; import org.apache.commons.io.IOUtils; import org.junit.Test; @@ -23,12 +22,13 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; 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.*; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.AnyOf.anyOf; @@ -617,7 +617,7 @@ public void shouldReturnResponseWithConnectionOptionsAndCloseSocketAndSuppressCo "GET " + calculatePath("") + " HTTP/1.1" + NEW_LINE + "Content-Length: 0\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -632,9 +632,9 @@ public void shouldReturnResponseWithConnectionOptionsAndCloseSocketAndSuppressCo // and - socket is closed try { // flush data to increase chance that Java / OS notice socket has been closed - output.write("some_random_bytes".getBytes(Charsets.UTF_8)); + output.write("some_random_bytes".getBytes(StandardCharsets.UTF_8)); output.flush(); - output.write("some_random_bytes".getBytes(Charsets.UTF_8)); + output.write("some_random_bytes".getBytes(StandardCharsets.UTF_8)); output.flush(); TimeUnit.SECONDS.sleep(2); @@ -662,7 +662,7 @@ public void shouldReturnResponseWithConnectionOptionsAndCloseSocketAndSuppressCo "GET " + calculatePath("") + " HTTP/1.1" + NEW_LINE + "Content-Length: 0\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -704,11 +704,11 @@ public void shouldReturnErrorResponseForExpectationWithHttpError() throws Except "GET " + calculatePath("") + " HTTP/1.1" + NEW_LINE + "Content-Length: 0\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then - assertThat(IOUtils.toString(socket.getInputStream(), Charsets.UTF_8.name()), is("some_random_bytes")); + assertThat(IOUtils.toString(socket.getInputStream(), StandardCharsets.UTF_8.name()), is("some_random_bytes")); } finally { if (socket != null) { socket.close(); @@ -727,11 +727,11 @@ public void shouldReturnErrorResponseForExpectationWithHttpError() throws Except "GET " + calculatePath("") + " HTTP/1.1" + NEW_LINE + "Content-Length: 0\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then - assertThat(IOUtils.toString(sslSocket.getInputStream(), Charsets.UTF_8.name()), is("some_random_bytes")); + assertThat(IOUtils.toString(sslSocket.getInputStream(), StandardCharsets.UTF_8.name()), is("some_random_bytes")); } finally { if (sslSocket != null) { sslSocket.close(); @@ -764,11 +764,11 @@ public void shouldReturnErrorResponseForExpectationWithHttpErrorAndVerifyRequest "GET " + calculatePath("http_error") + " HTTP/1.1" + NEW_LINE + "Content-Length: 0\r" + NEW_LINE + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then - assertThat(IOUtils.toString(socket.getInputStream(), Charsets.UTF_8.name()), is("some_random_bytes")); + assertThat(IOUtils.toString(socket.getInputStream(), StandardCharsets.UTF_8.name()), is("some_random_bytes")); } finally { if (socket != null) { socket.close(); diff --git a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingProxyIntegrationTest.java b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingProxyIntegrationTest.java index a7259aa7d..2b1804c27 100644 --- a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingProxyIntegrationTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingProxyIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.proxy.direct; -import com.google.common.base.Charsets; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -10,6 +9,7 @@ import java.io.OutputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; import static org.mockserver.test.Assert.assertContains; @@ -55,7 +55,7 @@ public void shouldForwardRequestsUsingSocketDirectlyHeadersOnly() throws Excepti "Host: localhost:" + echoServer.getPort() + "\r\n" + "X-Test: test_headers_only\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -82,10 +82,10 @@ public void shouldForwardRequestsUsingSocketDirectlyHeadersAndBody() throws Exce "GET /test_headers_and_body HTTP/1.1\r\n" + "Host: localhost:" + echoServer.getPort() + "\r\n" + "X-Test: test_headers_and_body\r\n" + - "Content-Length:" + "an_example_body".getBytes(Charsets.UTF_8).length + "\r\n" + + "Content-Length:" + "an_example_body".getBytes(StandardCharsets.UTF_8).length + "\r\n" + "\r\n" + "an_example_body" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -114,7 +114,7 @@ public void shouldForwardRequestsUsingSocketDirectlyNotFound() throws Exception "GET /not_found HTTP/1.1\r\n" + "Host: localhost:" + echoServer.getPort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then diff --git a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingSecureProxyIntegrationTest.java b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingSecureProxyIntegrationTest.java index 8da350911..9726c6d68 100644 --- a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingSecureProxyIntegrationTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/direct/NettyPortForwardingSecureProxyIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.proxy.direct; -import com.google.common.base.Charsets; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -11,6 +10,7 @@ import java.io.OutputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; import static org.mockserver.model.HttpRequest.request; import static org.mockserver.socket.SSLSocketFactory.sslSocketFactory; @@ -62,7 +62,7 @@ public void shouldForwardRequestsUsingSocketDirectlyHeadersOnly() throws Excepti "Host: localhost:" + echoServer.getPort() + "\r\n" + "X-Test: test_headers_only\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -97,10 +97,10 @@ public void shouldForwardRequestsUsingSocketDirectlyHeadersAndBody() throws Exce "GET /test_headers_and_body HTTP/1.1\r\n" + "Host: localhost:" + echoServer.getPort() + "\r\n" + "X-Test: test_headers_and_body\r\n" + - "Content-Length:" + "an_example_body".getBytes(Charsets.UTF_8).length + "\r\n" + + "Content-Length:" + "an_example_body".getBytes(StandardCharsets.UTF_8).length + "\r\n" + "\r\n" + "an_example_body" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then @@ -138,7 +138,7 @@ public void shouldForwardRequestsUsingSocketDirectlyNotFound() throws Exception "GET /not_found HTTP/1.1\r\n" + "Host: localhost:" + echoServer.getPort() + "\r\n" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then diff --git a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/socks/NettyHttpProxySOCKSIntegrationTest.java b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/socks/NettyHttpProxySOCKSIntegrationTest.java index 7a3f5de3c..d114fd80f 100644 --- a/mockserver-netty/src/test/java/org/mockserver/integration/proxy/socks/NettyHttpProxySOCKSIntegrationTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/integration/proxy/socks/NettyHttpProxySOCKSIntegrationTest.java @@ -1,6 +1,5 @@ package org.mockserver.integration.proxy.socks; -import com.google.common.base.Charsets; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -32,6 +31,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.*; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; @@ -234,7 +234,7 @@ public Socket connectSocket( // then assertEquals(HttpStatusCode.OK_200.code(), response.getStatusLine().getStatusCode()); - assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), Charsets.UTF_8)); + assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), StandardCharsets.UTF_8)); // and mockServerClient.verify( @@ -302,7 +302,7 @@ public Socket connectSocket( // then assertEquals(HttpStatusCode.OK_200.code(), response.getStatusLine().getStatusCode()); - assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), Charsets.UTF_8)); + assertEquals("an_example_body", new String(EntityUtils.toByteArray(response.getEntity()), StandardCharsets.UTF_8)); // and mockServerClient.verify( @@ -356,10 +356,10 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { "GET /test_headers_and_body HTTP/1.1\r\n" + "Host: localhost:" + (useTLS ? secureEchoServer.getPort() : insecureEchoServer.getPort()) + "\r\n" + "X-Test: test_headers_and_body\r\n" + - "Content-Length:" + "an_example_body".getBytes(Charsets.UTF_8).length + "\r\n" + + "Content-Length:" + "an_example_body".getBytes(StandardCharsets.UTF_8).length + "\r\n" + "\r\n" + "an_example_body" + "\r\n" - ).getBytes(Charsets.UTF_8)); + ).getBytes(StandardCharsets.UTF_8)); output.flush(); // then diff --git a/mockserver-netty/src/test/java/org/mockserver/proxy/direct/DirectProxyUnificationHandlerTest.java b/mockserver-netty/src/test/java/org/mockserver/proxy/direct/DirectProxyUnificationHandlerTest.java index 1b88098c7..93099023c 100644 --- a/mockserver-netty/src/test/java/org/mockserver/proxy/direct/DirectProxyUnificationHandlerTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/proxy/direct/DirectProxyUnificationHandlerTest.java @@ -22,7 +22,7 @@ import java.io.IOException; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.Is.is; diff --git a/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerSOCKSErrorTest.java b/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerSOCKSErrorTest.java index 1ffff512e..3ce4671a8 100644 --- a/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerSOCKSErrorTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerSOCKSErrorTest.java @@ -18,7 +18,7 @@ import org.mockserver.proxy.socks.SocksProxyHandler; import org.mockserver.scheduler.Scheduler; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.Is.is; diff --git a/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerTest.java b/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerTest.java index 44a6b22dd..2ee85d5e9 100644 --- a/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerTest.java +++ b/mockserver-netty/src/test/java/org/mockserver/proxy/http/HttpProxyUnificationInitializerTest.java @@ -20,7 +20,7 @@ import java.io.IOException; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.Is.is;