Source Code Cross Referenced for NestableRuntimeExceptionTestCase.java in  » Library » Apache-common-lang » org » apache » commons » lang » exception » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang.exception 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.lang.exception;
018:
019:        import java.io.ByteArrayOutputStream;
020:        import java.io.EOFException;
021:        import java.io.PrintStream;
022:
023:        import junit.framework.Test;
024:        import junit.framework.TestSuite;
025:        import junit.textui.TestRunner;
026:
027:        /**
028:         * Tests the org.apache.commons.lang.exception.NestableRuntimeException class.
029:         *
030:         * @author <a href="mailto:steven@caswell.name">Steven Caswell</a>
031:         * @version $Id: NestableRuntimeExceptionTestCase.java 437554 2006-08-28 06:21:41Z bayard $
032:         */
033:        public class NestableRuntimeExceptionTestCase extends
034:                AbstractNestableTestCase {
035:
036:            /**
037:             * Construct a new instance of
038:             * <code>NestableRuntimeExceptionTestCase</code>.
039:             *
040:             * @param name test case name
041:             */
042:            public NestableRuntimeExceptionTestCase(String name) {
043:                super (name);
044:            }
045:
046:            /**
047:             * Sets up instance variables required by this test case.
048:             */
049:            public void setUp() {
050:            }
051:
052:            /**
053:             * Returns the test suite
054:             *
055:             * @return the test suite
056:             */
057:            public static Test suite() {
058:                return new TestSuite(NestableRuntimeExceptionTestCase.class);
059:            }
060:
061:            /**
062:             * Tears down instance variables required by this test case.
063:             */
064:            public void tearDown() {
065:            }
066:
067:            /**
068:             * Command line entry point for running the test suite.
069:             *
070:             * @param args array of command line arguments
071:             */
072:            public static void main(String args[]) {
073:                TestRunner.run(suite());
074:            }
075:
076:            /**
077:             * @see AbstractNestableTestCase#getNestable()
078:             */
079:            public Nestable getNestable() {
080:                return new NestableRuntimeException();
081:            }
082:
083:            /**
084:             * @see AbstractNestableTestCase#getNestable(Nestable)
085:             */
086:            public Nestable getNestable(Nestable n) {
087:                return new NestableRuntimeException((Throwable) n);
088:            }
089:
090:            /**
091:             * @see AbstractNestableTestCase#getNestable(String)
092:             */
093:            public Nestable getNestable(String msg) {
094:                return new NestableRuntimeException(msg);
095:            }
096:
097:            /**
098:             * @see AbstractNestableTestCase#getNestable(Throwable)
099:             */
100:            public Nestable getNestable(Throwable t) {
101:                return new NestableRuntimeException(t);
102:            }
103:
104:            /**
105:             * @see AbstractNestableTestCase#getNestable(String, Throwable)
106:             */
107:            public Nestable getNestable(String msg, Throwable t) {
108:                return new NestableRuntimeException(msg, t);
109:            }
110:
111:            /**
112:             * @see AbstractNestableTestCase#getNestable(String, Nestable)
113:             */
114:            public Nestable getNestable(String msg, Nestable n) {
115:                return new NestableRuntimeException(msg, (Throwable) n);
116:            }
117:
118:            /**
119:             * @see AbstractNestableTestCase#getTester1(Throwable)
120:             */
121:            public Nestable getTester1(Throwable t) {
122:                return new NestableRuntimeExceptionTester1(t);
123:            }
124:
125:            /**
126:             * @see AbstractNestableTestCase#getTester1(Nestable)
127:             */
128:            public Nestable getTester1(Nestable n) {
129:                return new NestableRuntimeExceptionTester1((Throwable) n);
130:            }
131:
132:            /**
133:             * @see AbstractNestableTestCase#getTester1(String, Throwable)
134:             */
135:            public Nestable getTester1(String msg, Throwable t) {
136:                return new NestableRuntimeExceptionTester1(msg, t);
137:            }
138:
139:            /**
140:             * @see AbstractNestableTestCase#getTester1(String, Nestable)
141:             */
142:            public Nestable getTester1(String msg, Nestable n) {
143:                return new NestableRuntimeExceptionTester1(msg, (Throwable) n);
144:            }
145:
146:            /**
147:             * @see AbstractNestableTestCase#getTester1Class()
148:             */
149:            public Class getTester1Class() {
150:                return NestableRuntimeExceptionTester1.class;
151:            }
152:
153:            /**
154:             * @see AbstractNestableTestCase#getTester2(String, Throwable)
155:             */
156:            public Nestable getTester2(String msg, Throwable t) {
157:                return new NestableRuntimeExceptionTester2(msg, t);
158:            }
159:
160:            /**
161:             * @see AbstractNestableTestCase#getTester2(String, Nestable)
162:             */
163:            public Nestable getTester2(String msg, Nestable n) {
164:                return new NestableRuntimeExceptionTester2(msg, (Throwable) n);
165:            }
166:
167:            /**
168:             * @see AbstractNestableTestCase#getTester2Class()
169:             */
170:            public Class getTester2Class() {
171:                return NestableRuntimeExceptionTester2.class;
172:            }
173:
174:            /**
175:             * @see AbstractNestableTestCase#getThrowable(String)
176:             */
177:            public Throwable getThrowable(String msg) {
178:                return new EOFException(msg);
179:            }
180:
181:            /**
182:             * @see AbstractNestableTestCase#getThrowableClass()
183:             */
184:            public Class getThrowableClass() {
185:                return EOFException.class;
186:            }
187:
188:            /**
189:             * @see AbstractNestableTestCase#getBaseThrowableClass()
190:             */
191:            public Class getBaseThrowableClass() {
192:                return RuntimeException.class;
193:            }
194:
195:            public void testSpecificPrintStackTrace() {
196:                // Test printStackTrac()
197:                // Replace System.err with our own PrintStream so that we can obtain
198:                // and check the printStrackTrace output
199:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
200:                PrintStream ps = new PrintStream(baos);
201:                NestableRuntimeException ne = new NestableRuntimeException(
202:                        "outer", new NestableRuntimeException("inner",
203:                                new Exception("another exception")));
204:                for (int i = 0; i < 2; i++) {
205:                    if (i == 0) {
206:                        // Test printStackTrac()
207:                        // Replace System.err with our own PrintStream so that we can
208:                        // obtain and check the printStrackTrace output
209:                        PrintStream err = System.err;
210:                        System.setErr(ps);
211:                        ne.printStackTrace();
212:                        // Restore the System.err
213:                        System.setErr(err);
214:                    } else {
215:                        // Test printStackTrace(PrintStream)
216:                        ne.printStackTrace(ps);
217:                    }
218:                }
219:                String msg = baos.toString();
220:                assertTrue(
221:                        "printStackTrace() starts with outer message",
222:                        msg
223:                                .startsWith("org.apache.commons.lang.exception.NestableRuntimeException: outer"));
224:                assertTrue(
225:                        "printStackTrace() contains 1st nested message",
226:                        msg
227:                                .indexOf("Caused by: org.apache.commons.lang.exception.NestableRuntimeException: inner") >= 0);
228:                assertTrue(
229:                        "printStackTrace() contains 2nd nested message",
230:                        msg
231:                                .indexOf("Caused by: java.lang.Exception: another exception") >= 0);
232:                assertTrue(
233:                        "printStackTrace() inner message after outer message",
234:                        msg
235:                                .indexOf("org.apache.commons.lang.exception.NestableRuntimeException: outer") < msg
236:                                .indexOf("Caused by: org.apache.commons.lang.exception.NestableRuntimeException: inner"));
237:                assertTrue(
238:                        "printStackTrace() cause message after inner message",
239:                        msg
240:                                .indexOf("Caused by: org.apache.commons.lang.exception.NestableRuntimeException: inner") < msg
241:                                .indexOf("Caused by: java.lang.Exception: another exception"));
242:            }
243:
244:        }
245:
246:        /**
247:         * First nestable tester implementation for use in test cases.
248:         */
249:        class NestableRuntimeExceptionTester1 extends NestableRuntimeException {
250:            public NestableRuntimeExceptionTester1() {
251:                super ();
252:            }
253:
254:            public NestableRuntimeExceptionTester1(String reason,
255:                    Throwable cause) {
256:                super (reason, cause);
257:            }
258:
259:            public NestableRuntimeExceptionTester1(String reason) {
260:                super (reason);
261:            }
262:
263:            public NestableRuntimeExceptionTester1(Throwable cause) {
264:                super (cause);
265:            }
266:
267:        }
268:
269:        /**
270:         * Second nestable tester implementation.
271:         */
272:        class NestableRuntimeExceptionTester2 extends NestableRuntimeException {
273:            public NestableRuntimeExceptionTester2() {
274:                super ();
275:            }
276:
277:            public NestableRuntimeExceptionTester2(String reason,
278:                    Throwable cause) {
279:                super (reason, cause);
280:            }
281:
282:            public NestableRuntimeExceptionTester2(String reason) {
283:                super (reason);
284:            }
285:
286:            public NestableRuntimeExceptionTester2(Throwable cause) {
287:                super(cause);
288:            }
289:
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.