mirror of
https://github.com/google/gson.git
synced 2026-03-13 08:01:59 +08:00
Add boundary tests for JsonTreeWriter.endArray() error handling (#2988)
* Add boundary tests for JsonTreeWriter.endArray() error handling * Update JsonTreeWriterTest.java
This commit is contained in:
@@ -281,4 +281,25 @@ public final class JsonTreeWriterTest {
|
||||
"getSerializeNulls()");
|
||||
MoreAsserts.assertOverridesMethods(JsonWriter.class, JsonTreeWriter.class, ignoredMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndArrayOnEmptyStackThrows() {
|
||||
JsonTreeWriter writer = new JsonTreeWriter();
|
||||
assertThrows(IllegalStateException.class, () -> writer.endArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndArrayWithPendingNameThrows() throws IOException {
|
||||
JsonTreeWriter writer = new JsonTreeWriter();
|
||||
writer.beginObject();
|
||||
writer.name("test");
|
||||
assertThrows(IllegalStateException.class, () -> writer.endArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndArrayWhenStackTopIsNotArrayThrows() throws IOException {
|
||||
JsonTreeWriter writer = new JsonTreeWriter();
|
||||
writer.beginObject();
|
||||
assertThrows(IllegalStateException.class, () -> writer.endArray());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user