@Test public void testNext() { final String[] twoFacit = two.split("\n"); final int[] c = {0}; Parser p = new Parser( twoLineIs, new ParserCallback<String>() { public void callback(String s) { assertEquals(twoFacit[c[CALLBACK_COUNT]++], s); // Test the correct lines are sent } }); while (p.hasNext()) p.next(); assertEquals( c[CALLBACK_COUNT], twoFacit.length); // Test that the callback has been called for each item exactly once }
@Test public void testIgnoreNext() { final String[] fiveFacit = five.split("\n"); final int[] c = {0, 0}; // callback, ignored Parser p = new Parser( fiveLineIs, new ParserCallback<String>() { public void callback(String s) { assertEquals( fiveFacit[c[IGNORED_COUNT] + c[CALLBACK_COUNT]++], s); // Test the correct lines are sent } }); while (true) { if (!p.hasNext()) break; p.next(); if (!p.hasNext()) break; p.ignoreNext(); c[IGNORED_COUNT]++; } assertEquals( c[CALLBACK_COUNT] + c[IGNORED_COUNT], fiveFacit .length); // Test that the callback count + ignored is total the length of the facit }
@Test public void testHasNext() { Parser p1 = new Parser( emptyIs, new ParserCallback<String>() { public void callback(String s) {} }); assertFalse(p1.hasNext()); Parser p2 = new Parser( oneLineIs, new ParserCallback<String>() { public void callback(String s) {} }); assertTrue(p2.hasNext()); p2.next(); assertFalse(p2.hasNext()); }