LEFT | RIGHT |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.dev.test.numbers; | 3 package com.ibm.icu.dev.test.numbers; |
4 | 4 |
5 import static org.junit.Assert.assertEquals; | 5 import static org.junit.Assert.assertEquals; |
6 import static org.junit.Assert.assertNotEquals; | 6 import static org.junit.Assert.assertNotEquals; |
7 import static org.junit.Assert.assertTrue; | 7 import static org.junit.Assert.assertTrue; |
8 import static org.junit.Assert.fail; | 8 import static org.junit.Assert.fail; |
9 | 9 |
10 import java.io.ByteArrayInputStream; | 10 import java.io.ByteArrayInputStream; |
11 import java.io.ByteArrayOutputStream; | 11 import java.io.ByteArrayOutputStream; |
12 import java.io.IOException; | 12 import java.io.IOException; |
13 import java.io.ObjectInputStream; | 13 import java.io.ObjectInputStream; |
14 import java.io.ObjectOutputStream; | 14 import java.io.ObjectOutputStream; |
15 import java.lang.reflect.Field; | 15 import java.lang.reflect.Field; |
16 import java.lang.reflect.InvocationTargetException; | 16 import java.lang.reflect.InvocationTargetException; |
17 import java.lang.reflect.Method; | 17 import java.lang.reflect.Method; |
18 import java.lang.reflect.Modifier; | 18 import java.lang.reflect.Modifier; |
| 19 import java.lang.reflect.Parameter; |
19 import java.math.BigDecimal; | 20 import java.math.BigDecimal; |
20 import java.math.BigInteger; | 21 import java.math.BigInteger; |
21 import java.math.MathContext; | 22 import java.math.MathContext; |
22 import java.math.RoundingMode; | 23 import java.math.RoundingMode; |
23 import java.util.HashSet; | 24 import java.util.HashSet; |
24 import java.util.Set; | 25 import java.util.Set; |
25 | 26 |
26 import org.junit.Test; | 27 import org.junit.Test; |
27 | 28 |
| 29 import com.ibm.icu.dev.test.serializable.SerializableTestUtility; |
28 import com.ibm.icu.impl.number.Parse.ParseMode; | 30 import com.ibm.icu.impl.number.Parse.ParseMode; |
29 import com.ibm.icu.impl.number.PatternString; | 31 import com.ibm.icu.impl.number.PatternString; |
30 import com.ibm.icu.impl.number.Properties; | 32 import com.ibm.icu.impl.number.Properties; |
31 import com.ibm.icu.impl.number.formatters.CurrencyFormat.CurrencyStyle; | 33 import com.ibm.icu.impl.number.formatters.CurrencyFormat.CurrencyStyle; |
32 import com.ibm.icu.impl.number.formatters.PaddingFormat.PaddingLocation; | 34 import com.ibm.icu.impl.number.formatters.PaddingFormat.PadPosition; |
33 import com.ibm.icu.impl.number.rounders.SignificantDigitsRounder.SignificantDigi
tsMode; | 35 import com.ibm.icu.impl.number.rounders.SignificantDigitsRounder.SignificantDigi
tsMode; |
34 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle; | 36 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle; |
35 import com.ibm.icu.text.CurrencyPluralInfo; | 37 import com.ibm.icu.text.CurrencyPluralInfo; |
36 import com.ibm.icu.text.MeasureFormat.FormatWidth; | 38 import com.ibm.icu.text.MeasureFormat.FormatWidth; |
37 import com.ibm.icu.util.Currency; | 39 import com.ibm.icu.util.Currency; |
38 import com.ibm.icu.util.Currency.CurrencyUsage; | 40 import com.ibm.icu.util.Currency.CurrencyUsage; |
39 import com.ibm.icu.util.MeasureUnit; | 41 import com.ibm.icu.util.MeasureUnit; |
40 import com.ibm.icu.util.ULocale; | 42 import com.ibm.icu.util.ULocale; |
41 | 43 |
42 public class PropertiesTest { | 44 public class PropertiesTest { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 assertEquals( | 94 assertEquals( |
93 "Method " + setterName + " does not return correct type", | 95 "Method " + setterName + " does not return correct type", |
94 Properties.class, | 96 Properties.class, |
95 setter.getReturnType()); | 97 setter.getReturnType()); |
96 } catch (NoSuchMethodException e) { | 98 } catch (NoSuchMethodException e) { |
97 fail("Could not find method " + setterName + " for field " + field); | 99 fail("Could not find method " + setterName + " for field " + field); |
98 continue; | 100 continue; |
99 } catch (SecurityException e) { | 101 } catch (SecurityException e) { |
100 fail("Could not access method " + setterName + " for field " + field); | 102 fail("Could not access method " + setterName + " for field " + field); |
101 continue; | 103 continue; |
| 104 } |
| 105 |
| 106 // Check for parameter name equality. |
| 107 // The parameter name is not always available, depending on compiler setti
ngs. |
| 108 Parameter param = setter.getParameters()[0]; |
| 109 if (!param.getName().subSequence(0, 3).equals("arg")) { |
| 110 assertEquals("Parameter name should equal field name", field.getName(),
param.getName()); |
102 } | 111 } |
103 | 112 |
104 try { | 113 try { |
105 // Check for default value (should be null for objects) | 114 // Check for default value (should be null for objects) |
106 if (field.getType() != Integer.TYPE && field.getType() != Boolean.TYPE)
{ | 115 if (field.getType() != Integer.TYPE && field.getType() != Boolean.TYPE)
{ |
107 Object default0 = getter.invoke(p0); | 116 Object default0 = getter.invoke(p0); |
108 assertEquals("Field " + field + " has non-null default value:", null,
default0); | 117 assertEquals("Field " + field + " has non-null default value:", null,
default0); |
109 } | 118 } |
110 | 119 |
111 // Check for getter, equals, and hash code behavior | 120 // Check for getter, equals, and hash code behavior |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } else if (type == MathContext.class) { | 253 } else if (type == MathContext.class) { |
245 if (seed == 0) return null; | 254 if (seed == 0) return null; |
246 RoundingMode[] modes = RoundingMode.values(); | 255 RoundingMode[] modes = RoundingMode.values(); |
247 return new MathContext(seed, modes[seed % modes.length]); | 256 return new MathContext(seed, modes[seed % modes.length]); |
248 | 257 |
249 } else if (type == MeasureUnit.class) { | 258 } else if (type == MeasureUnit.class) { |
250 if (seed == 0) return null; | 259 if (seed == 0) return null; |
251 Object[] units = MeasureUnit.getAvailable().toArray(); | 260 Object[] units = MeasureUnit.getAvailable().toArray(); |
252 return units[seed % units.length]; | 261 return units[seed % units.length]; |
253 | 262 |
254 } else if (type == PaddingLocation.class) { | 263 } else if (type == PadPosition.class) { |
255 if (seed == 0) return null; | 264 if (seed == 0) return null; |
256 PaddingLocation[] values = PaddingLocation.values(); | 265 PadPosition[] values = PadPosition.values(); |
257 return values[seed % values.length]; | 266 return values[seed % values.length]; |
258 | 267 |
259 } else if (type == ParseMode.class) { | 268 } else if (type == ParseMode.class) { |
260 if (seed == 0) return null; | 269 if (seed == 0) return null; |
261 ParseMode[] values = ParseMode.values(); | 270 ParseMode[] values = ParseMode.values(); |
262 return values[seed % values.length]; | 271 return values[seed % values.length]; |
263 | 272 |
264 } else if (type == RoundingMode.class) { | 273 } else if (type == RoundingMode.class) { |
265 if (seed == 0) return null; | 274 if (seed == 0) return null; |
266 RoundingMode[] values = RoundingMode.values(); | 275 RoundingMode[] values = RoundingMode.values(); |
(...skipping 27 matching lines...) Expand all Loading... |
294 | 303 |
295 // Read from byte stream | 304 // Read from byte stream |
296 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes
)); | 305 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes
)); |
297 Object obj = ois.readObject(); | 306 Object obj = ois.readObject(); |
298 ois.close(); | 307 ois.close(); |
299 Properties props1 = (Properties) obj; | 308 Properties props1 = (Properties) obj; |
300 | 309 |
301 // Test equality | 310 // Test equality |
302 assertEquals("Did not round-trip through serialization", props0, props1); | 311 assertEquals("Did not round-trip through serialization", props0, props1); |
303 } | 312 } |
| 313 |
| 314 /** Handler for serialization compatibility test suite. */ |
| 315 public static class PropertiesHandler implements SerializableTestUtility.Handl
er { |
| 316 |
| 317 @Override |
| 318 public Object[] getTestObjects() { |
| 319 return new Object[] { |
| 320 new Properties(), |
| 321 PatternString.parseToProperties("x#,##0.00%"), |
| 322 new Properties().setCompactStyle(CompactStyle.LONG).setMinimumExponentDi
gits(2) |
| 323 }; |
| 324 } |
| 325 |
| 326 @Override |
| 327 public boolean hasSameBehavior(Object a, Object b) { |
| 328 return a.equals(b); |
| 329 } |
| 330 } |
304 } | 331 } |
LEFT | RIGHT |