From 912db55ba670e8ed0187aac131e102387ec0556d Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Fri, 2 Oct 2009 19:39:09 +0000 Subject: [PATCH] Added test for hasNext on JsonStreamParser. --- .../com/google/gson/JsonStreamParserTest.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/gson/src/test/java/com/google/gson/JsonStreamParserTest.java b/gson/src/test/java/com/google/gson/JsonStreamParserTest.java index 989321ec..e053ad48 100644 --- a/gson/src/test/java/com/google/gson/JsonStreamParserTest.java +++ b/gson/src/test/java/com/google/gson/JsonStreamParserTest.java @@ -22,30 +22,48 @@ import java.util.NoSuchElementException; /** * Unit tests for {@link JsonStreamParser} - * + * * @author Inderjeet Singh */ public class JsonStreamParserTest extends TestCase { + private JsonStreamParser parser; + @Override + protected void setUp() throws Exception { + super.setUp(); + parser = new JsonStreamParser("'one' 'two'"); + } + public void testParseTwoStrings() { - JsonStreamParser parser = new JsonStreamParser("'one' 'two'"); String actualOne = parser.next().getAsString(); assertEquals("one", actualOne); String actualTwo = parser.next().getAsString(); assertEquals("two", actualTwo); } - + public void testIterator() { - Iterator parser = new JsonStreamParser("'one' 'two'"); assertTrue(parser.hasNext()); assertEquals("one", parser.next().getAsString()); assertTrue(parser.hasNext()); assertEquals("two", parser.next().getAsString()); assertFalse(parser.hasNext()); } - + + public void testNoSideEffectForHasNext() throws Exception { + assertTrue(parser.hasNext()); + assertTrue(parser.hasNext()); + assertTrue(parser.hasNext()); + assertEquals("one", parser.next().getAsString()); + + assertTrue(parser.hasNext()); + assertTrue(parser.hasNext()); + assertEquals("two", parser.next().getAsString()); + + assertFalse(parser.hasNext()); + assertFalse(parser.hasNext()); + } + public void testCallingNextBeyondAvailableInput() { - Iterator parser = new JsonStreamParser("'one' 'two'"); parser.next(); parser.next(); try {