Avoid using UTF-8 characters in source code

Using UTF-8 in the source can be problematic on platforms that are
not configured to use UTF-8 by default. This commit replaces a number
of strings with UTF-8 characters in them with an equivalent ASCII
string that uses unicode character escapes.
This commit is contained in:
Andy Wilkinson
2015-09-23 20:51:44 +01:00
parent 318ed18233
commit f8cbb3b63c
3 changed files with 11 additions and 8 deletions

View File

@@ -87,17 +87,18 @@ public class HttpRequestSnippetTests {
@Test
public void postRequestWithCharset() throws IOException {
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
this.snippet.expectHttpRequest("post-request-with-charset").withContents(
httpRequest(RequestMethod.POST, "/foo")
.header(HttpHeaders.HOST, "localhost")
.header("Content-Type", "text/plain;charset=UTF-8")
.content("こんにちわ, 世界")); // Hello, World in Japanese
.content(japaneseContent));
new HttpRequestSnippet().document(new OperationBuilder(
"post-request-with-charset", this.snippet.getOutputDirectory())
.request("http://localhost/foo").method("POST")
.header("Content-Type", "text/plain;charset=UTF-8").content("こんにちわ, 世界")
.build());
.header("Content-Type", "text/plain;charset=UTF-8")
.content(japaneseContent).build());
}
@Test

View File

@@ -86,13 +86,14 @@ public class HttpResponseSnippetTests {
@Test
public void responseWithCharset() throws IOException {
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
this.snippet.expectHttpResponse("response-with-charset").withContents(
httpResponse(HttpStatus.OK).header("Content-Type",
"text/plain;charset=UTF-8").content("コンテンツ"));
"text/plain;charset=UTF-8").content(japaneseContent));
new HttpResponseSnippet().document(new OperationBuilder("response-with-charset",
this.snippet.getOutputDirectory()).response()
.header("Content-Type", "text/plain;charset=UTF-8").content("コンテンツ")
.build());
.header("Content-Type", "text/plain;charset=UTF-8")
.content(japaneseContent).build());
}
@Test

View File

@@ -48,12 +48,13 @@ public class PatternReplacingContentModifierTests {
@Test
public void encodingIsPreserved() {
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
Pattern pattern = Pattern.compile("[0-9]+");
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
pattern, "<<number>>");
assertThat(contentModifier.modifyContent("こんにちわ, 世界 123".getBytes(),
assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(),
new MediaType("text", "plain", Charset.forName("UTF-8"))),
is(equalTo("こんにちわ, 世界 <<number>>".getBytes())));
is(equalTo((japaneseContent + " <<number>>").getBytes())));
}
}