1 26 27 package net.sourceforge.groboutils.util.throwable.v1; 28 29 import org.easymock.EasyMock; 30 import org.easymock.MockControl; 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 35 import org.apache.log4j.Logger; 36 37 38 45 public class ThrowableParserUTest extends TestCase 46 { 47 50 private static final Class THIS_CLASS = ThrowableParserUTest.class; 51 private static final Logger LOG = Logger.getLogger( THIS_CLASS ); 52 53 public ThrowableParserUTest( String name ) 54 { 55 super( name ); 56 } 57 58 59 62 66 protected void setUp() throws Exception 67 { 68 super.setUp(); 69 70 } 72 73 74 77 78 public void testConstructor1() 79 { 80 try 81 { 82 new ThrowableParser( null ); 83 fail("did not throw an IllegalArgumentException"); 84 } 85 catch (IllegalArgumentException e) 86 { 87 } 89 } 90 91 92 public void testConstructor2() 93 { 94 new ThrowableParser( new Throwable () ); 95 } 96 97 98 101 public void testTrace1() 102 { 103 Throwable t = new Throwable (); 104 t.fillInStackTrace(); 105 ThrowableParser tp = new ThrowableParser( t ); 106 boolean foundMe = false; 107 while (true) 108 { 109 StackTraceLineParser stlp = tp.next(); 110 if (stlp == null) break; 111 112 LOG.info( "Stack trace: "+stlp ); 113 if (stlp.getClassName().equals( this.getClass().getName() )) 114 { 115 LOG.debug( "foundMe == true" ); 116 foundMe = true; 117 } 118 else 119 { 120 LOG.debug( "stack class name '"+stlp.getClassName()+ 121 "' did not match this class name '"+ 122 this.getClass().getName() + "'." ); 123 } 124 } 125 LOG.debug( "foundMe == "+foundMe ); 126 assertTrue( 127 "Did not find this class in the stack trace.", 128 foundMe ); 129 } 130 131 132 133 134 137 138 141 142 public static Test suite() 143 { 144 TestSuite suite = new TestSuite( THIS_CLASS ); 145 146 157 158 return suite; 159 } 160 161 public static void main( String [] args ) 162 { 163 String [] name = { THIS_CLASS.getName() }; 164 165 168 junit.textui.TestRunner.main( name ); 169 } 170 171 172 176 protected void tearDown() throws Exception 177 { 178 180 181 super.tearDown(); 182 } 183 } 184 185 | Popular Tags |