Added test for hasNext on JsonStreamParser.
This commit is contained in:
parent
0c2106f2ff
commit
912db55ba6
@ -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<JsonElement> 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<JsonElement> parser = new JsonStreamParser("'one' 'two'");
|
||||
parser.next();
|
||||
parser.next();
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user