Code example for Scanner

Methods: close, hasNext, next

0
         
        // test socket inputStream 
        os.write("aab b".getBytes());
        serverSocket.close();
 
        s = new Scanner(client);
        pattern = Pattern.compile("a+b");
        assertTrue(s.hasNext(pattern));
        assertEquals("aab", s.next(pattern));
        assertFalse(s.hasNext(pattern));
        try { 
            s.next(pattern);
            fail("should throw InputMismatchException");
        } catch (InputMismatchException e) {
            // Expected 
        } 
    } 
     
    /** 
     * @throws IOException 
     * @tests java.util.Scanner#hasNext(String)