]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/core/src/com/ibm/icu/dev/test/serializable/ExceptionTests.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / core / src / com / ibm / icu / dev / test / serializable / ExceptionTests.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1996-2009, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  *\r
7  */\r
8 \r
9 package com.ibm.icu.dev.test.serializable;\r
10 \r
11 import java.util.Locale;\r
12 \r
13 import com.ibm.icu.impl.IllegalIcuArgumentException;\r
14 import com.ibm.icu.impl.InvalidFormatException;\r
15 import com.ibm.icu.impl.locale.LocaleSyntaxException;\r
16 import com.ibm.icu.text.ArabicShapingException;\r
17 import com.ibm.icu.text.StringPrepParseException;\r
18 import com.ibm.icu.util.IllformedLocaleException;\r
19 import com.ibm.icu.util.UResourceTypeMismatchException;\r
20 \r
21 /**\r
22  * @author emader\r
23  *\r
24  * TODO To change the template for this generated type comment go to\r
25  * Window - Preferences - Java - Code Style - Code Templates\r
26  */\r
27 public class ExceptionTests\r
28 {\r
29     static abstract class ExceptionHandler implements SerializableTest.Handler\r
30     {\r
31         abstract public Object[] getTestObjects();\r
32         \r
33         public boolean hasSameBehavior(Object a, Object b)\r
34         {\r
35             Exception ea = (Exception) a;\r
36             Exception eb = (Exception) b;\r
37             \r
38             return ea.toString().equals(eb.toString());\r
39         }\r
40     }\r
41     \r
42     static class ArabicShapingExceptionHandler extends ExceptionHandler\r
43     {\r
44         public Object[] getTestObjects()\r
45         {\r
46             Locale locales[] = SerializableTest.getLocales();\r
47             ArabicShapingException exceptions[] = new ArabicShapingException[locales.length];\r
48             \r
49             for (int i = 0; i < locales.length; i += 1) {\r
50                 exceptions[i] = new ArabicShapingException(locales[i].toString());\r
51             }\r
52             \r
53             return exceptions;\r
54         }\r
55     }\r
56     \r
57     static class StringPrepParseExceptionHandler extends ExceptionHandler\r
58     {\r
59         public Object[] getTestObjects()\r
60         {\r
61             Locale locales[] = SerializableTest.getLocales();\r
62             String rules = "This is a very odd little set of rules, just for testing, you know...";\r
63             StringPrepParseException exceptions[] = new StringPrepParseException[locales.length];\r
64             \r
65             for (int i = 0; i < locales.length; i += 1) {\r
66                 exceptions[i] = new StringPrepParseException(locales[i].toString(), i, rules, i);\r
67             }\r
68             \r
69             return exceptions;\r
70         }\r
71     }\r
72     \r
73     static class UResourceTypeMismatchExceptionHandler extends ExceptionHandler\r
74     {\r
75         public Object[] getTestObjects()\r
76         {\r
77             Locale locales[] = SerializableTest.getLocales();\r
78             UResourceTypeMismatchException exceptions[] = new UResourceTypeMismatchException[locales.length];\r
79             \r
80             for (int i = 0; i < locales.length; i += 1) {\r
81                 exceptions[i] = new UResourceTypeMismatchException(locales[i].toString());\r
82             }\r
83             \r
84             return exceptions;\r
85         }\r
86     }\r
87     \r
88     static class InvalidFormatExceptionHandler extends ExceptionHandler\r
89     {\r
90         public Object[] getTestObjects()\r
91         {\r
92             Locale locales[] = SerializableTest.getLocales();\r
93             InvalidFormatException exceptions[] = new InvalidFormatException[locales.length];\r
94             \r
95             for (int i = 0; i < locales.length; i += 1) {\r
96                 exceptions[i] = new InvalidFormatException(locales[i].toString());\r
97             }\r
98             \r
99             return exceptions;\r
100         }\r
101     }\r
102 \r
103     static class IllformedLocaleExceptionHandler extends ExceptionHandler\r
104     {\r
105         public Object[] getTestObjects()\r
106         {\r
107             IllformedLocaleException[] exceptions = new IllformedLocaleException[2];\r
108             exceptions[0] = new IllformedLocaleException("msg1");\r
109             exceptions[1] = new IllformedLocaleException("msg2", 5);\r
110             return exceptions;\r
111         }\r
112         public boolean hasSameBehavior(Object a, Object b)\r
113         {\r
114             IllformedLocaleException ifeA = (IllformedLocaleException) a;\r
115             IllformedLocaleException ifeB = (IllformedLocaleException) b;\r
116             if (ifeA.getErrorIndex() != ifeB.getErrorIndex()) {\r
117                 return false;\r
118             }\r
119             return super.hasSameBehavior(a, b);\r
120         }\r
121     }\r
122 \r
123     static class LocaleSyntaxExceptionHandler extends ExceptionHandler\r
124     {\r
125         public Object[] getTestObjects()\r
126         {\r
127             LocaleSyntaxException[] exceptions = new LocaleSyntaxException[2];\r
128             exceptions[0] = new LocaleSyntaxException("msg1");\r
129             exceptions[1] = new LocaleSyntaxException("msg2", 5);\r
130             return exceptions;\r
131         }\r
132         public boolean hasSameBehavior(Object a, Object b)\r
133         {\r
134             LocaleSyntaxException ifeA = (LocaleSyntaxException) a;\r
135             LocaleSyntaxException ifeB = (LocaleSyntaxException) b;\r
136             if (ifeA.getErrorIndex() != ifeB.getErrorIndex()) {\r
137                 return false;\r
138             }\r
139             return super.hasSameBehavior(a, b);\r
140         }\r
141     }\r
142 \r
143     static class IllegalIcuArgumentExceptionHandler extends ExceptionHandler\r
144     {\r
145         public Object[] getTestObjects()\r
146         {\r
147             IllegalIcuArgumentException[] exceptions = {\r
148                 new IllegalIcuArgumentException("Bad argument FOO")\r
149             };\r
150             return exceptions;\r
151         }\r
152     }\r
153 \r
154     public static void main(String[] args)\r
155     {\r
156     }\r
157 }\r