Code example for PrintStream

Methods: write

0
    /** 
     * @tests java.io.PrintStream#write(int) 
     */ 
    public void test_writeI() { 
        // Test for method void java.io.PrintStream.write(int) 
        PrintStream os = new PrintStream(bos, true);
        os.write('t');
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        assertEquals("Incorrect char written", 't', bis.read());
    } 
 
    /** 
     * @tests java.io.PrintStream#append(char) 
     */ 
    public void test_appendChar() throws IOException { 
        char testChar = ' ';
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(out);
        printStream.append(testChar);
        printStream.flush();
        assertEquals(String.valueOf(testChar), out.toString());