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}
|
* Unit tests for {@link JsonStreamParser}
|
||||||
*
|
*
|
||||||
* @author Inderjeet Singh
|
* @author Inderjeet Singh
|
||||||
*/
|
*/
|
||||||
public class JsonStreamParserTest extends TestCase {
|
public class JsonStreamParserTest extends TestCase {
|
||||||
|
private JsonStreamParser parser;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
parser = new JsonStreamParser("'one' 'two'");
|
||||||
|
}
|
||||||
|
|
||||||
public void testParseTwoStrings() {
|
public void testParseTwoStrings() {
|
||||||
JsonStreamParser parser = new JsonStreamParser("'one' 'two'");
|
|
||||||
String actualOne = parser.next().getAsString();
|
String actualOne = parser.next().getAsString();
|
||||||
assertEquals("one", actualOne);
|
assertEquals("one", actualOne);
|
||||||
String actualTwo = parser.next().getAsString();
|
String actualTwo = parser.next().getAsString();
|
||||||
assertEquals("two", actualTwo);
|
assertEquals("two", actualTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIterator() {
|
public void testIterator() {
|
||||||
Iterator<JsonElement> parser = new JsonStreamParser("'one' 'two'");
|
|
||||||
assertTrue(parser.hasNext());
|
assertTrue(parser.hasNext());
|
||||||
assertEquals("one", parser.next().getAsString());
|
assertEquals("one", parser.next().getAsString());
|
||||||
assertTrue(parser.hasNext());
|
assertTrue(parser.hasNext());
|
||||||
assertEquals("two", parser.next().getAsString());
|
assertEquals("two", parser.next().getAsString());
|
||||||
assertFalse(parser.hasNext());
|
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() {
|
public void testCallingNextBeyondAvailableInput() {
|
||||||
Iterator<JsonElement> parser = new JsonStreamParser("'one' 'two'");
|
|
||||||
parser.next();
|
parser.next();
|
||||||
parser.next();
|
parser.next();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user