KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > throwable > v1 > ThrowableParserUTest


1 /*
2  * @(#)ThrowableParserUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

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 /**
39  * Tests the ThrowableParser class.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2003/02/10 22:52:43 $
43  * @since March 17, 2002
44  */

45 public class ThrowableParserUTest extends TestCase
46 {
47     //-------------------------------------------------------------------------
48
// Standard JUnit Class-specific declarations
49

50     private static final Class JavaDoc THIS_CLASS = ThrowableParserUTest.class;
51     private static final Logger LOG = Logger.getLogger( THIS_CLASS );
52     
53     public ThrowableParserUTest( String JavaDoc name )
54     {
55         super( name );
56     }
57
58     
59     //-------------------------------------------------------------------------
60
// setup
61

62     /**
63      *
64      * @exception Exception thrown under any exceptional condition.
65      */

66     protected void setUp() throws Exception JavaDoc
67     {
68         super.setUp();
69         
70         // set ourself up
71
}
72
73
74     //-------------------------------------------------------------------------
75
// Tests
76

77     
78     public void testConstructor1()
79     {
80         try
81         {
82             new ThrowableParser( null );
83             fail("did not throw an IllegalArgumentException");
84         }
85         catch (IllegalArgumentException JavaDoc e)
86         {
87             // test exception?
88
}
89     }
90     
91     
92     public void testConstructor2()
93     {
94         new ThrowableParser( new Throwable JavaDoc() );
95     }
96     
97     
98     /**
99      * More of a UIT than a UT...
100      */

101     public void testTrace1()
102     {
103         Throwable JavaDoc t = new Throwable JavaDoc();
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     //-------------------------------------------------------------------------
135
// Helpers
136

137     
138     //-------------------------------------------------------------------------
139
// Standard JUnit declarations
140

141     
142     public static Test suite()
143     {
144         TestSuite suite = new TestSuite( THIS_CLASS );
145         
146         // Test the implementation's interface conformity.
147
/*
148         suite.addTest( IxUTestI.suite(
149             new ImplementationCreator[] {
150                 new ImplementationCreator() {
151                     public Object createImplementedObject() {
152                         // XXXXXXXXXXXXXXXXXXXXXXXX
153                     }
154                 },
155             } ) );
156         */

157         
158         return suite;
159     }
160     
161     public static void main( String JavaDoc[] args )
162     {
163         String JavaDoc[] name = { THIS_CLASS.getName() };
164         
165         // junit.textui.TestRunner.main( name );
166
// junit.swingui.TestRunner.main( name );
167

168         junit.textui.TestRunner.main( name );
169     }
170     
171     
172     /**
173      *
174      * @exception Exception thrown under any exceptional condition.
175      */

176     protected void tearDown() throws Exception JavaDoc
177     {
178         // tear ourself down
179

180         
181         super.tearDown();
182     }
183 }
184
185
Popular Tags