Code example for Console

Methods: readLine

0
        String line = console.readLine();
        assertEquals("hello world", line);
    } 
 
    public void test_readLine_LString_LObject() { 
        String line = console.readLine("%d %s", 2, "Please input a line of string to test:");
        assertEquals("hello world", line);
        String prompt = new String(((ByteArrayOutputStream)out).toByteArray());
        assertEquals("2 Please input a line of string to test:", prompt);
    } 
 
    public void test_readPassword() { 
        // Since we cannot set the echo off by using the mock input and output 
        // stream, so IOException will be thrown. 
        try { 
            console.readPassword();
            fail();
        } catch (IOError expected) {
        } 
    }