Code example for CharArrayWriter

Methods: toString

0
        // Test for method void 
        // java.lang.reflect.InvocationTargetException.printStackTrace() 
        try { 
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(bao);
            PrintStream oldErr = System.err;
            System.setErr(ps);
            InvocationTargetException ite = new InvocationTargetException(null);
            ite.printStackTrace();
            System.setErr(oldErr);
 
            String s = new String(bao.toByteArray());
 
            assertTrue("Incorrect Stack trace: " + s, s != null
                    && s.length() > 300);
        } catch (Exception e) {
            fail("printStackTrace() caused exception : " + e.getMessage());
        } 
    } 
 
    /**