Package org.apache.commons.math.exception.util

Examples of org.apache.commons.math.exception.util.Localizable


    /**
     * Tests the printStackTrace() operation.
     */
    public void testPrintStackTrace() {
        Localizable outMsg = new DummyLocalizable("outer message");
        Localizable inMsg = new DummyLocalizable("inner message");
        MathException cause = new MathConfigurationException(inMsg);
        MathException ex = new MathException(cause, outMsg);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        ex.printStackTrace(ps);
View Full Code Here


    /**
     * Test serialization
     */
    public void testSerialization() {
        Localizable outMsg = new DummyLocalizable("outer message");
        Localizable inMsg = new DummyLocalizable("inner message");
        MathException cause = new MathConfigurationException(inMsg);
        MathException ex = new MathException(cause, outMsg);
        MathException image = (MathException) TestUtils.serializeAndRecover(ex);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        ex.printStackTrace(ps);
        String stack = baos.toString();

        ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
        PrintStream ps2 = new PrintStream(baos2);
        image.printStackTrace(ps2);
        String stack2 = baos2.toString();

        // See if JDK supports nested exceptions.  If not, stack trace of
        // inner exception will not be serialized
        boolean jdkSupportsNesting = false;
        try {
            Throwable.class.getDeclaredMethod("getCause", new Class[0]);
            jdkSupportsNesting = true;
        } catch (NoSuchMethodException e) {
            jdkSupportsNesting = false;
        }

        if (jdkSupportsNesting) {
            assertEquals(stack, stack2);
        } else {
            assertTrue(stack2.indexOf(inMsg.getSourceString()) != -1);
            assertTrue(stack2.indexOf("MathConfigurationException") != -1);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.exception.util.Localizable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.