22
33import com .jsoniter .any .Any ;
44import com .jsoniter .spi .JsonException ;
5+ import java .io .ByteArrayInputStream ;
56import java .io .IOException ;
67import java .io .InputStream ;
78import junit .framework .TestCase ;
@@ -35,7 +36,7 @@ public void testLoadMore() throws IOException {
3536 // Check buffer was not expanded
3637 assertEquals (initialBufferSize , jsonIterator .buf .length );
3738
38- // Case #2: Data does fit into initial buffer, autoresizing off
39+ // Case #2: Data does not fit into initial buffer, autoresizing off
3940 initialBufferSize = originalContent .length () / 2 ;
4041 jsonIterator = JsonIterator .parse (getSluggishInputStream (src ), initialBufferSize , 0 );
4142 jsonIterator .readObject ();
@@ -59,6 +60,15 @@ public void testLoadMore() throws IOException {
5960 assertEquals (originalContent , parsedString .toString ());
6061 // Check buffer was expanded exactly once
6162 assertEquals (initialBufferSize + autoExpandBufferStep , jsonIterator .buf .length );
63+
64+ // Case #4: Data does not fit (but largest string does) into initial buffer, autoresizing on
65+ initialBufferSize = originalContent .length () + 2 ;
66+ jsonIterator = JsonIterator .parse (new ByteArrayInputStream (src ), initialBufferSize , 0 );
67+ jsonIterator .readObject ();
68+ parsedString = jsonIterator .readAny ();
69+ assertEquals (originalContent , parsedString .toString ());
70+ // Check buffer was expanded exactly once
71+ assertEquals (initialBufferSize , jsonIterator .buf .length );
6272 }
6373
6474 private static InputStream getSluggishInputStream (final byte [] src ) {
0 commit comments