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