Source Code Cross Referenced for ThrowableHelper_Test.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.lang;
007:
008:        import java.util.Locale;
009:
010:        import junit.framework.TestCase;
011:
012:        /**
013:         * The <code>ThrowableHelper_Test</code> class tests
014:         * <code>ThrowableHelper</code> class.
015:         *
016:         * @version $Revision: 34826 $
017:         *
018:         * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
019:         **/
020:        public class ThrowableHelper_Test extends TestCase {
021:            /** Class version identifier. */
022:            public static final String RCS_ID = "@(#) $Header$";
023:
024:            /**
025:             * Run all the test cases defined in the class.
026:             *
027:             * @param args not used
028:             **/
029:            public static void main(String[] args) {
030:                junit.textui.TestRunner.run(suite());
031:            }
032:
033:            /**
034:             * Build a test suite using reflection.
035:             *
036:             * @return test suite for the class
037:             **/
038:            public static junit.framework.TestSuite suite() {
039:                return new junit.framework.TestSuite(ThrowableHelper_Test.class);
040:            }
041:
042:            /**
043:             * Setup for each test method.
044:             **/
045:            public void setUp() {
046:            }
047:
048:            /**
049:             * Tear down for each test method.
050:             **/
051:            public void tearDown() {
052:            }
053:
054:            public ThrowableHelper_Test(String name) {
055:                super (name);
056:            }
057:
058:            public void testGetDefaultHandler() {
059:                ThrowableHandler defaultHandler = ThrowableHelper
060:                        .getDefaultHandler(null);
061:
062:                String defaultHandlerClass = defaultHandler.getClass()
063:                        .getName();
064:
065:                String handlerClass = "";
066:
067:                verifyEquals(defaultHandlerClass, "");
068:
069:                verifyEquals(defaultHandlerClass, "someUnknownClass");
070:
071:                // Trigger a InstantiationException
072:                verifyEquals(defaultHandlerClass,
073:                        "java.lang.reflect.Constructor");
074:
075:                // Trigger an IllegalAccessException
076:                verifyEquals(defaultHandlerClass,
077:                        "java.lang.reflect.ReflectAccess");
078:
079:                // Trigger an ExceptionInInitializerError...
080:            }
081:
082:            private void verifyEquals(String correctClassName, String className) {
083:                ThrowableHandler handler = ThrowableHelper
084:                        .getDefaultHandler(className);
085:
086:                TestCase.assertEquals(correctClassName, handler.getClass()
087:                        .getName());
088:            }
089:
090:            public void testGetInternationalizedMessage() {
091:                try {
092:                    ThrowableHelper.getInternationalizedMessage(null, null,
093:                            null);
094:
095:                    TestCase.fail("Expected a NullPointerException");
096:                } catch (NullPointerException x) {
097:                    ;//correct
098:                }
099:
100:                try {
101:                    ThrowableHelper.getInternationalizedMessage(
102:                            ThrowableHelper_Test.class, null, null);
103:
104:                    TestCase.fail("Expected a NullPointerException");
105:                } catch (NullPointerException x) {
106:                    ;//correct
107:                }
108:
109:                String i18nMessage = ThrowableHelper
110:                        .getInternationalizedMessage(
111:                                ThrowableHelper_Test.class,
112:                                "some.error.message", null);
113:
114:                i18nMessage = ThrowableHelper.getInternationalizedMessage(
115:                        ThrowableHelper_Test.class, "some.error.message",
116:                        new String[] { null });
117:
118:                i18nMessage = ThrowableHelper.getInternationalizedMessage(
119:                        ThrowableHelper_Test.class, "some.error.message",
120:                        new String[] { "one", "two" });
121:            }
122:
123:            public void testGetLocalizedMessage() {
124:                Throwable throwable = new Exception();
125:
126:                String l10nMessage = ThrowableHelper
127:                        .getLocalizedMessage(throwable);
128:
129:                l10nMessage = ThrowableHelper.getLocalizedMessage(throwable,
130:                        java.util.Locale.getDefault());
131:
132:                String i18nMessage = ThrowableHelper
133:                        .getInternationalizedMessage(
134:                                ThrowableHelper_Test.class, "some.error",
135:                                new String[] { "one", "two" });
136:
137:                l10nMessage = ThrowableHelper.getLocalizedMessage(i18nMessage,
138:                        Locale.getDefault());
139:
140:                l10nMessage = ThrowableHelper.getLocalizedMessage(
141:                        "not_a_well_formed_i18n_Message", Locale.getDefault());
142:            }
143:
144:            public void testInitCause() {
145:                try {
146:                    ThrowableHelper.initCause(null, null);
147:
148:                    TestCase.fail("Expected NullPointerException");
149:                } catch (NullPointerException x) {
150:                    ;//correct
151:                }
152:
153:                ThrowableHelper.initCause(new Throwable(), new Exception());
154:            }
155:
156:            public void testCreate() {
157:                ThrowableHelper.create(IllegalAccessException.class,
158:                        ThrowableHelper_Test.class, "some.property",
159:                        new String[] { "one", "two" }, new Error(
160:                                "my random cause "));
161:            }
162:
163:            public void testHandle() {
164:                ThrowableHelper.handle(new Throwable("something"));
165:
166:                ThrowableHelper.handle(ThrowableHelper_Test.class,
167:                        "some.error", new String[] { "one", "two" }, new Error(
168:                                "my cause"));
169:            }
170:        }
171:
172:        /**
173:         * The <code>ExceptionInInitializerHandler</code> class tests
174:         * <code>ThrowableHelper</code> class.
175:         *
176:         * @version $Revision: 34826 $
177:         *
178:         * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
179:         **/
180:        class ExceptionInInitializerHandler implements  ThrowableHandler {
181:            /*
182:              static
183:              {
184:              String somethingNull = null;
185:             
186:              // Trigger a NullPointerException during static initialization.
187:              somethingNull.length();
188:              }
189:             */
190:
191:            /**
192:             * Handles the condition specified in the parameters. The handler
193:             * can use the client class to resolve the property name of the
194:             * error message, and generate a localized message from the
195:             * optional objects.
196:             *
197:             * @param client client calling the handle method
198:             *
199:             * @param name property name associated with error message
200:             * 
201:             * @param objects objects associated with the error message, or
202:             * <code>null</code>
203:             *
204:             * @param cause throwable condition which caused the error, or
205:             * <code>null</code>
206:             *
207:             * @throws NullPointerException if client or property is
208:             * <code>null</code>
209:             **/
210:            public void handle(Class client, String name, String[] objects,
211:                    Throwable cause) {
212:                ;//do nothing
213:            }
214:        }
215:
216:        /**
217:         * The <code>IllegalAccessHandler</code> class tests
218:         * <code>ThrowableHelper</code> class.
219:         *
220:         * @version $Revision: 34826 $
221:         *
222:         * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
223:         **/
224:        class IllegalAccessHandler implements  ThrowableHandler {
225:            protected IllegalAccessHandler(String something) {
226:            }
227:
228:            /**
229:             * Handles the condition specified in the parameters. The handler
230:             * can use the client class to resolve the property name of the
231:             * error message, and generate a localized message from the
232:             * optional objects.
233:             *
234:             * @param client client calling the handle method
235:             *
236:             * @param name property name associated with error message
237:             * 
238:             * @param objects objects associated with the error message, or
239:             * <code>null</code>
240:             *
241:             * @param cause throwable condition which caused the error, or
242:             * <code>null</code>
243:             *
244:             * @throws NullPointerException if client or property is
245:             * <code>null</code>
246:             **/
247:            public void handle(Class client, String name, String[] objects,
248:                    Throwable cause) {
249:                ;//do nothing
250:            }
251:        }
252:
253:        /**
254:         * The <code>InstantiationExceptionHandler</code> class tests
255:         * <code>ThrowableHelper</code> class.
256:         *
257:         * @version $Revision: 34826 $
258:         *
259:         * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
260:         **/
261:        class InstantiationExceptionHandler implements  ThrowableHandler {
262:            /**
263:             * Hide the constructor to trigger the instantiation exception.
264:             **/
265:            private InstantiationExceptionHandler() {
266:            }
267:
268:            /**
269:             * Handles the condition specified in the parameters. The handler
270:             * can use the client class to resolve the property name of the
271:             * error message, and generate a localized message from the
272:             * optional objects.
273:             *
274:             * @param client client calling the handle method
275:             *
276:             * @param name property name associated with error message
277:             * 
278:             * @param objects objects associated with the error message, or
279:             * <code>null</code>
280:             *
281:             * @param cause throwable condition which caused the error, or
282:             * <code>null</code>
283:             *
284:             * @throws NullPointerException if client or property is
285:             * <code>null</code>
286:             **/
287:            public void handle(Class client, String name, String[] objects,
288:                    Throwable cause) {
289:                ;//do nothing
290:            }
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.