Skip to content

Commit

Permalink
Doc google#40: Add tests for setting strictness and lenient to JsonRe…
Browse files Browse the repository at this point in the history
…aderTest
  • Loading branch information
marten-voorberg committed Mar 1, 2023
1 parent 5e64e3c commit 0d65c62
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@

@SuppressWarnings("resource")
public final class JsonReaderTest {

@Test
public void testSetLenientTrue() {
JsonReader reader = new JsonReader(reader("{}"));
reader.setLenient(true);
assertThat(reader.getStrictness()).isEqualTo(Strictness.LENIENT);
}

@Test
public void testSetLenientFalse() {
JsonReader reader = new JsonReader(reader("{}"));
reader.setLenient(false);
assertThat(reader.getStrictness()).isEqualTo(Strictness.DEFAULT);
}

@Test
public void testSetStrictness() {
JsonReader reader = new JsonReader(reader("{}"));
reader.setStrictness(Strictness.STRICT);
assertThat(reader.getStrictness()).isEqualTo(Strictness.STRICT);
}

@Test
public void testSetStrictnessNull() {
JsonReader reader = new JsonReader(reader("{}"));
try {
reader.setStrictness(null);
fail();
} catch (NullPointerException expected) {
//OK: It should not be possible to set the strictness to null.
}
}

@Test
public void testEscapedNewlineNotAllowedInStrictMode() throws IOException {
String json = "\"\\\n\"";
Expand Down

0 comments on commit 0d65c62

Please sign in to comment.