Source Code Cross Referenced for TestThrowableList.java in  » Parser » JTopas » de » susebox » java » lang » 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 » Parser » JTopas » de.susebox.java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TestThrowableList.java: JUnit test for ThrowableList implementations
003:         *
004:         * Copyright (C) 2002 Heiko Blau
005:         *
006:         * This file belongs to the Susebox Java core test suite.
007:         * The Susebox Java core test suite is free software; you can redistribute it 
008:         * and/or modify it under the terms of the GNU Lesser General Public License as 
009:         * published by the Free Software Foundation; either version 2.1 of the License, 
010:         * or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful, but WITHOUT
013:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
014:         * FITNESS FOR A PARTICULAR PURPOSE. 
015:         * See the GNU Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public License along 
018:         * with the Susebox Java core test suite. If not, write to the
019:         *
020:         *   Free Software Foundation, Inc.
021:         *   59 Temple Place, Suite 330, 
022:         *   Boston, MA 02111-1307 
023:         *   USA
024:         *
025:         * or check the Internet: http://www.fsf.org
026:         *
027:         * The Susebox Java core test suite uses the test framework JUnit by Kent Beck 
028:         * and Erich Gamma. You should have received a copy of their JUnit licence 
029:         * agreement along with the Susebox Java test suite.
030:         *
031:         * We do NOT provide the JUnit archive junit.jar nessecary to compile and run 
032:         * our tests, since we assume, that You  either have it already or would like 
033:         * to get the current release Yourself. 
034:         * Please visit either:
035:         *   http://sourceforge.net/projects/junit
036:         * or
037:         *   http://junit.org
038:         * to obtain JUnit.
039:         *
040:         * Contact:
041:         *   email: heiko@susebox.de 
042:         */
043:
044:        package de.susebox.java.lang;
045:
046:        //-----------------------------------------------------------------------------
047:        // Imports
048:        //
049:        import java.text.MessageFormat;
050:
051:        import junit.framework.Test;
052:        import junit.framework.TestCase;
053:        import junit.framework.TestSuite;
054:        import junit.framework.Assert;
055:
056:        import de.susebox.TestUtilities;
057:
058:        //-----------------------------------------------------------------------------
059:        // Class TestThrowableList
060:        //
061:
062:        /**<p>
063:         * This class tests the functionality of the {@link ThrowableList} interface
064:         * through various implementing classes.
065:         *</p>
066:         *
067:         * @see     ThrowableList
068:         * @see     ExtRuntimeException
069:         * @author  Heiko Blau
070:         */
071:        public class TestThrowableList extends TestCase {
072:
073:            //---------------------------------------------------------------------------
074:            // properties
075:            //
076:
077:            //---------------------------------------------------------------------------
078:            // main method
079:            //
080:
081:            /**
082:             * call this method to invoke the tests
083:             */
084:            public static void main(String[] args) {
085:                String[] tests = { TestThrowableList.class.getName() };
086:
087:                TestUtilities.run(tests, args);
088:            }
089:
090:            //---------------------------------------------------------------------------
091:            // suite method
092:            //
093:
094:            /**
095:             * Implementation of the JUnit method <code>suite</code>. For each set of test
096:             * properties one or more tests are instantiated.
097:             *
098:             * @return a test suite
099:             */
100:            public static Test suite() {
101:                TestSuite suite = new TestSuite(TestThrowableList.class
102:                        .getName());
103:
104:                suite.addTest(new TestThrowableList("testWrappedThrowable"));
105:                suite.addTest(new TestThrowableList("testThrowableList"));
106:                suite.addTest(new TestThrowableList("testMessageFormatting"));
107:                return suite;
108:            }
109:
110:            //---------------------------------------------------------------------------
111:            // Constructor
112:            //
113:
114:            /**
115:             * Default constructor. Standard input {@link java.lang.System#in} is used
116:             * to construct the input stream reader.
117:             */
118:            public TestThrowableList(String test) {
119:                super (test);
120:            }
121:
122:            //---------------------------------------------------------------------------
123:            // Fixture setup and release
124:            //
125:
126:            /**
127:             * Sets up the fixture, for example, open a network connection.
128:             * This method is called before a test is executed.
129:             */
130:            protected void setUp() throws Exception {
131:            }
132:
133:            /**
134:             * Tears down the fixture, for example, close a network connection.
135:             * This method is called after a test is executed.
136:             */
137:            protected void tearDown() throws Exception {
138:            }
139:
140:            //---------------------------------------------------------------------------
141:            // test cases
142:            //
143:
144:            /**
145:             * Test wrapped exceptions. The wrapping exception is only a thin layer around
146:             * the real one.
147:             */
148:            public void testWrappedThrowable() throws Throwable {
149:                String msg = "This is an illegal argument.";
150:                IllegalArgumentException argEx = new IllegalArgumentException(
151:                        msg);
152:                ExtRuntimeException rtEx = new ExtRuntimeException(argEx);
153:                ExtIndexOutOfBoundsException indexEx = new ExtIndexOutOfBoundsException(
154:                        argEx);
155:                ExtIndexOutOfBoundsException bigEx = new ExtIndexOutOfBoundsException(
156:                        rtEx);
157:
158:                assertTrue("rtEx: Wrapper exception not recognized.", rtEx
159:                        .isWrapper());
160:                assertTrue("rtEx: Didn't retrieve the wrapped exception.", rtEx
161:                        .getCause() == argEx);
162:                assertTrue("rtEx: Messages not equal.", rtEx.getMessage()
163:                        .equals(argEx.getMessage()));
164:
165:                assertTrue("indexEx: Wrapper exception not recognized.",
166:                        indexEx.isWrapper());
167:                assertTrue("indexEx: Didn't retrieve the wrapped exception.",
168:                        indexEx.getCause() == argEx);
169:                assertTrue("indexEx: Messages not equal.", indexEx.getMessage()
170:                        .equals(argEx.getMessage()));
171:
172:                assertTrue("bigEx: Wrapper exception not recognized.", bigEx
173:                        .isWrapper());
174:                assertTrue(
175:                        "bigEx: Didn't retrieve the first wrapped exception.",
176:                        bigEx.getCause() == rtEx);
177:                assertTrue(
178:                        "bigEx: Didn't retrieve the second wrapped exception.",
179:                        ((ThrowableList) bigEx.getCause()).getCause() == argEx);
180:                assertTrue("bigEx: Messages not equal.", bigEx.getMessage()
181:                        .equals(argEx.getMessage()));
182:            }
183:
184:            /**
185:             * Test nested exceptions.
186:             */
187:            public void testThrowableList() throws Throwable {
188:                String format = "This is exception no {0} of class {1}.";
189:                String msg = "Message without format parameters.";
190:                ExtRuntimeException rtEx1 = new ExtRuntimeException(format,
191:                        new Object[] { new Integer(1),
192:                                ExtRuntimeException.class });
193:                ExtRuntimeException rtEx2 = new ExtRuntimeException(rtEx1,
194:                        format, new Object[] { new Integer(2),
195:                                ExtRuntimeException.class });
196:                ExtIndexOutOfBoundsException indexEx = new ExtIndexOutOfBoundsException(
197:                        rtEx2, msg);
198:
199:                assertTrue("rtEx1: False wrapper exception.", !rtEx1
200:                        .isWrapper());
201:                assertTrue("rtEx2: False wrapper exception.", !rtEx2
202:                        .isWrapper());
203:                assertTrue("indexEx: False wrapper exception.", !indexEx
204:                        .isWrapper());
205:                assertTrue("rtEx2: Didn't retrieve the nested exception.",
206:                        rtEx2.getCause() == rtEx1);
207:                assertTrue(
208:                        "indexEx: Didn't retrieve the first nested exception.",
209:                        indexEx.getCause() == rtEx2);
210:                assertTrue(
211:                        "indexEx: Didn't retrieve the second nested exception.",
212:                        ((ThrowableList) indexEx.getCause()).getCause() == rtEx1);
213:                assertTrue("rtEx1: Format not found.",
214:                        rtEx1.getFormat() == format);
215:                assertTrue("rtEx2: Format not found.",
216:                        rtEx2.getFormat() == format);
217:                assertTrue("indexEx: Format not found.",
218:                        indexEx.getFormat() == msg);
219:            }
220:
221:            /**
222:             * Test the message formatting
223:             */
224:            public void testMessageFormatting() throws Throwable {
225:                String format = "Class {0}, reason \"{1}\", user {2}.";
226:                Object[] paras = new Object[] { ExtRuntimeException.class,
227:                        "bad weather", "myself" };
228:                ExtRuntimeException rtEx = new ExtRuntimeException(format,
229:                        paras);
230:
231:                assertTrue("Format not found.", rtEx.getFormat() == format);
232:
233:                String str1 = MessageFormat.format(format, paras);
234:                String str2 = rtEx.getMessage();
235:                assertTrue("Formating failed. Expected \"" + str1
236:                        + "\", got \"" + str2 + "\".", str1.equals(str2));
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.