Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split testWriteHtmlSafe into Two Separate Test Cases for Improved Test Granularity #2653

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions gson/src/test/java/com/google/gson/MixedStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,22 @@ public void testReadNulls() {
}

@Test
public void testWriteHtmlSafe() {
public void testWriteHtmlSafeWithEscaping() {
List<String> contents = Arrays.asList("<", ">", "&", "=", "'");
Type type = new TypeToken<List<String>>() {}.getType();

StringWriter writer = new StringWriter();
new Gson().toJson(contents, type, new JsonWriter(writer));
assertThat(writer.toString())
.isEqualTo("[\"\\u003c\",\"\\u003e\",\"\\u0026\",\"\\u003d\",\"\\u0027\"]");
}

@Test
public void testWriteHtmlSafeWithoutEscaping() {
List<String> contents = Arrays.asList("<", ">", "&", "=", "'");
Type type = new TypeToken<List<String>>() {}.getType();

writer = new StringWriter();
StringWriter writer = new StringWriter();
new GsonBuilder().disableHtmlEscaping().create().toJson(contents, type, new JsonWriter(writer));
assertThat(writer.toString()).isEqualTo("[\"<\",\">\",\"&\",\"=\",\"'\"]");
}
Expand Down