Code example for JSONTokener

Methods: next

0
    /** 
     * Tests the next method using expected number of characters. 
     */ 
    public void testNext_ExpectedNumberOfCharacters() 
    { 
        jsontokener = new JSONTokener("abc123");
        String expectedAbc = "";
        String expectedBlank = "";
        try 
        { 
            expectedAbc = jsontokener.next(3);
            expectedBlank = jsontokener.next(0);
            jsontokener.next(7);
            fail("Should have thrown exception.");
        } catch (JSONException e)
        { 
            assertEquals("abc", expectedAbc);
            assertEquals("", expectedBlank);
            assertEquals("Substring bounds error at 7 [character 8 line 1]", e.getMessage());
        } 
    }