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