1 61 62 package org.jaxen; 63 64 65 import java.io.PrintWriter ; 66 import java.io.StringWriter ; 67 68 import junit.framework.TestCase; 69 70 71 75 public class JaxenExceptionTest extends TestCase { 76 77 public JaxenExceptionTest(String name) { 78 super(name); 79 } 80 81 public void testMessageIsNonNull() { 82 JaxenException ex = new JaxenException("Hello"); 83 assertEquals("Hello", ex.getMessage()); 84 } 85 86 public void testPrintStackTrace() { 87 StringIndexOutOfBoundsException cause = new StringIndexOutOfBoundsException ("1234"); 88 JaxenException ex = new JaxenException(cause); 89 StringWriter out = new StringWriter (); 90 PrintWriter pw = new PrintWriter (out); 91 ex.printStackTrace(pw); 92 pw.close(); 93 String trace = out.toString(); 94 assertEquals(-1, trace.indexOf("Root cause:")); 95 assertTrue(trace.indexOf("Caused by: java.lang.StringIndexOutOfBoundsException") > 0); 96 assertTrue(trace.indexOf("1234") > 0); 97 } 98 99 } 100 | Popular Tags |