Code example for Scanner

Methods: close, match, next, nextBoolean

0
    /** 
     * @tests java.util.Scanner#match() 
     */ 
    public void test_match() { 
        MatchResult result ;
        s = new Scanner("1 2 ");
        try { 
            s.match();
            fail("should throw IllegalStateException");
        } catch (IllegalStateException e) {
            // Expected 
        } 
        assertEquals("1", s.next());
        assertEquals("2", s.next());
        result = s.match();
        assertEquals(2, result.start());
        assertEquals(3, result.end());
        assertEquals(2, result.start(0));
        assertEquals(3, result.end(0));
        assertEquals("2", result.group());
        assertEquals("2", result.group(0));
        assertEquals(0, result.groupCount());
        try { 
            result.start(1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // Expected 
        } 
        try { 
            s.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected 
        } 
        try { 
            s.match();
            fail("should throw IllegalStateException");
        } catch (IllegalStateException e) {
            // Expected 
        }