Skip to content

Commit

Permalink
Split testWriteHtmlSafe into Two Separate Test Cases for Improved T…
Browse files Browse the repository at this point in the history
…est Granularity (#2653)

* Split testWriteHtmlSafe into two test case to improve the Test Granularity

* Style violations fixed
  • Loading branch information
Codegass committed Mar 20, 2024
1 parent 8bc62cb commit 04eb52d
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 04eb52d

Please sign in to comment.