2 *******************************************************************************
\r
3 * Copyright (C) 1996-2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
9 package com.ibm.icu.dev.test.serializable;
\r
11 import java.util.Locale;
\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
24 * TODO To change the template for this generated type comment go to
\r
25 * Window - Preferences - Java - Code Style - Code Templates
\r
27 public class ExceptionTests
\r
29 static abstract class ExceptionHandler implements SerializableTest.Handler
\r
31 abstract public Object[] getTestObjects();
\r
33 public boolean hasSameBehavior(Object a, Object b)
\r
35 Exception ea = (Exception) a;
\r
36 Exception eb = (Exception) b;
\r
38 return ea.toString().equals(eb.toString());
\r
42 static class ArabicShapingExceptionHandler extends ExceptionHandler
\r
44 public Object[] getTestObjects()
\r
46 Locale locales[] = SerializableTest.getLocales();
\r
47 ArabicShapingException exceptions[] = new ArabicShapingException[locales.length];
\r
49 for (int i = 0; i < locales.length; i += 1) {
\r
50 exceptions[i] = new ArabicShapingException(locales[i].toString());
\r
57 static class StringPrepParseExceptionHandler extends ExceptionHandler
\r
59 public Object[] getTestObjects()
\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
65 for (int i = 0; i < locales.length; i += 1) {
\r
66 exceptions[i] = new StringPrepParseException(locales[i].toString(), i, rules, i);
\r
73 static class UResourceTypeMismatchExceptionHandler extends ExceptionHandler
\r
75 public Object[] getTestObjects()
\r
77 Locale locales[] = SerializableTest.getLocales();
\r
78 UResourceTypeMismatchException exceptions[] = new UResourceTypeMismatchException[locales.length];
\r
80 for (int i = 0; i < locales.length; i += 1) {
\r
81 exceptions[i] = new UResourceTypeMismatchException(locales[i].toString());
\r
88 static class InvalidFormatExceptionHandler extends ExceptionHandler
\r
90 public Object[] getTestObjects()
\r
92 Locale locales[] = SerializableTest.getLocales();
\r
93 InvalidFormatException exceptions[] = new InvalidFormatException[locales.length];
\r
95 for (int i = 0; i < locales.length; i += 1) {
\r
96 exceptions[i] = new InvalidFormatException(locales[i].toString());
\r
103 static class IllformedLocaleExceptionHandler extends ExceptionHandler
\r
105 public Object[] getTestObjects()
\r
107 IllformedLocaleException[] exceptions = new IllformedLocaleException[2];
\r
108 exceptions[0] = new IllformedLocaleException("msg1");
\r
109 exceptions[1] = new IllformedLocaleException("msg2", 5);
\r
112 public boolean hasSameBehavior(Object a, Object b)
\r
114 IllformedLocaleException ifeA = (IllformedLocaleException) a;
\r
115 IllformedLocaleException ifeB = (IllformedLocaleException) b;
\r
116 if (ifeA.getErrorIndex() != ifeB.getErrorIndex()) {
\r
119 return super.hasSameBehavior(a, b);
\r
123 static class LocaleSyntaxExceptionHandler extends ExceptionHandler
\r
125 public Object[] getTestObjects()
\r
127 LocaleSyntaxException[] exceptions = new LocaleSyntaxException[2];
\r
128 exceptions[0] = new LocaleSyntaxException("msg1");
\r
129 exceptions[1] = new LocaleSyntaxException("msg2", 5);
\r
132 public boolean hasSameBehavior(Object a, Object b)
\r
134 LocaleSyntaxException ifeA = (LocaleSyntaxException) a;
\r
135 LocaleSyntaxException ifeB = (LocaleSyntaxException) b;
\r
136 if (ifeA.getErrorIndex() != ifeB.getErrorIndex()) {
\r
139 return super.hasSameBehavior(a, b);
\r
143 static class IllegalIcuArgumentExceptionHandler extends ExceptionHandler
\r
145 public Object[] getTestObjects()
\r
147 IllegalIcuArgumentException[] exceptions = {
\r
148 new IllegalIcuArgumentException("Bad argument FOO")
\r
154 public static void main(String[] args)
\r