OSDN Git Service

Use GCC visibility to reduce the size of libdvm by 10%
[android-x86/dalvik.git] / libcore / text / src / test / java / org / apache / harmony / text / tests / java / text / NumberFormatTest.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.harmony.text.tests.java.text;
18
19 import dalvik.annotation.TestTargets;
20 import dalvik.annotation.TestLevel;
21 import dalvik.annotation.TestTargetNew;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.BrokenTest;
24 import tests.support.Support_Locale;
25
26 import junit.framework.TestCase;
27
28 import java.text.ChoiceFormat;
29 import java.text.DecimalFormat;
30 import java.text.FieldPosition;
31 import java.text.NumberFormat;
32 import java.text.ParseException;
33 import java.text.ParsePosition;
34 import java.util.Currency;
35 import java.util.Locale;
36
37 @TestTargetClass(NumberFormat.class)
38 public class NumberFormatTest extends TestCase {
39
40     /**
41      * @tests java.text.NumberFormat#format(java.lang.Object,
42      *        java.lang.StringBuffer, java.text.FieldPosition)
43      */
44     @TestTargetNew(
45         level = TestLevel.COMPLETE,
46         notes = "",
47         method = "format",
48         args = {java.lang.Object.class, java.lang.StringBuffer.class, java.text.FieldPosition.class}
49     )
50     public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
51         FieldPosition pos;
52         StringBuffer out;
53         DecimalFormat format = (DecimalFormat) NumberFormat
54                 .getInstance(Locale.US);
55
56         pos = new FieldPosition(0);
57         out = format.format(new Long(Long.MAX_VALUE), new StringBuffer(), pos);
58         assertEquals("Wrong result L1: " + out, "9,223,372,036,854,775,807",
59                 out.toString());
60
61         pos = new FieldPosition(0);
62         out = format.format(new Long(Long.MIN_VALUE), new StringBuffer(), pos);
63         assertEquals("Wrong result L2: " + out, "-9,223,372,036,854,775,808",
64                 out.toString());
65
66         pos = new FieldPosition(0);
67         out = format.format(new java.math.BigInteger(String
68                 .valueOf(Long.MAX_VALUE)), new StringBuffer(), pos);
69         assertEquals("Wrong result BI1: " + out, "9,223,372,036,854,775,807",
70                 out.toString());
71
72         pos = new FieldPosition(0);
73         out = format.format(new java.math.BigInteger(String
74                 .valueOf(Long.MIN_VALUE)), new StringBuffer(), pos);
75         assertEquals("Wrong result BI2: " + out, "-9,223,372,036,854,775,808",
76                 out.toString());
77
78         java.math.BigInteger big;
79         pos = new FieldPosition(0);
80         big = new java.math.BigInteger(String.valueOf(Long.MAX_VALUE))
81                 .add(new java.math.BigInteger("1"));
82         out = format.format(big, new StringBuffer(), pos);
83         assertEquals("Wrong result BI3: " + out, "9,223,372,036,854,775,808",
84                 out.toString());
85
86         pos = new FieldPosition(0);
87         big = new java.math.BigInteger(String.valueOf(Long.MIN_VALUE))
88                 .add(new java.math.BigInteger("-1"));
89         out = format.format(big, new StringBuffer(), pos);
90         assertEquals("Wrong result BI4: " + out, "-9,223,372,036,854,775,809",
91                 out.toString());
92
93         pos = new FieldPosition(0);
94         out = format.format(new java.math.BigDecimal("51.348"),
95                 new StringBuffer(), pos);
96         assertEquals("Wrong result BD1: " + out, "51.348", out.toString());
97
98         pos = new FieldPosition(0);
99         out = format.format(new java.math.BigDecimal("51"), new StringBuffer(),
100                 pos);
101         assertEquals("Wrong result BD2: " + out, "51", out.toString());
102
103     }
104
105     /**
106      * @tests java.text.NumberFormat#getIntegerInstance()
107      */
108     @TestTargetNew(
109         level = TestLevel.COMPLETE,
110         notes = "",
111         method = "getIntegerInstance",
112         args = {}
113     )
114     public void test_getIntegerInstance() throws ParseException {
115         // Test for method java.text.NumberFormat getIntegerInstance()
116         Locale origLocale = Locale.getDefault();
117         Locale.setDefault(Locale.US);
118
119         DecimalFormat format = (DecimalFormat) NumberFormat
120                 .getIntegerInstance();
121
122         assertEquals(
123                 "Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern",
124                 "#,##0", format.toPattern());
125         assertEquals(
126                 "Test2: NumberFormat.getIntegerInstance().format(35.76) returned wrong value",
127                 "36", format.format(35.76));
128         assertEquals(
129                 "Test3: NumberFormat.getIntegerInstance().parse(\"35.76\") returned wrong number",
130                 new Long(35), format.parse("35.76"));
131         assertEquals(
132                 "Test4: NumberFormat.getIntegerInstance().parseObject(\"35.76\") returned wrong number",
133                 new Long(35), format.parseObject("35.76"));
134         Locale.setDefault(origLocale);
135     }
136
137     /**
138      * @tests java.text.NumberFormat#getIntegerInstance(java.util.Locale)
139      */
140     @TestTargetNew(
141         level = TestLevel.COMPLETE,
142         notes = "",
143         method = "getIntegerInstance",
144         args = {java.util.Locale.class}
145     )
146     public void test_getIntegerInstanceLjava_util_Locale()
147             throws ParseException {
148         // Test for method java.text.NumberFormat
149         // getIntegerInstance(java.util.Locale)
150         Locale usLocale = Locale.US;
151         Locale arLocale = new Locale("ar", "AE");
152         // BEGIN android-added: use de_CH too.
153         Locale chLocale = new Locale("de", "CH");
154         // END android-added
155
156         Locale[] requiredLocales = {usLocale, chLocale};
157         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
158             // locale dependent test, bug 1943269
159             return;
160         }
161
162         DecimalFormat format = (DecimalFormat) NumberFormat
163                 .getIntegerInstance(usLocale);
164         assertEquals(
165                 "Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern",
166                 "#,##0", format.toPattern());
167         assertEquals(
168                 "Test2: NumberFormat.getIntegerInstance().format(-35.76) returned wrong value",
169                 "-36", format.format(-35.76));
170         assertEquals(
171                 "Test3: NumberFormat.getIntegerInstance().parse(\"-36\") returned wrong number",
172                 new Long(-36), format.parse("-36"));
173         assertEquals(
174                 "Test4: NumberFormat.getIntegerInstance().parseObject(\"-36\") returned wrong number",
175                 new Long(-36), format.parseObject("-36"));
176         assertEquals(
177                 "Test5: NumberFormat.getIntegerInstance().getMaximumFractionDigits() returned wrong value",
178                 0, format.getMaximumFractionDigits());
179         assertTrue(
180                 "Test6: NumberFormat.getIntegerInstance().isParseIntegerOnly() returned wrong value",
181                 format.isParseIntegerOnly());
182
183         // try with a locale that has a different integer pattern
184         // BEGIN android-added: try de_CH too
185         format = (DecimalFormat) NumberFormat.getIntegerInstance(chLocale);
186         assertEquals(
187                 "Test7: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).toPattern() returned wrong pattern",
188                 "#,##0", format.toPattern());
189         assertEquals(
190                 "Test8: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).format(-35.76) returned wrong value",
191                 "-36", format.format(-35.76));
192         assertEquals(
193                 "Test9: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).parse(\"-36-\") returned wrong number",
194                 new Long(-36), format.parse("-36"));
195         assertEquals(
196                 "Test10: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).parseObject(\"36-\") returned wrong number",
197                 new Long(-36), format.parseObject("-36"));
198
199         assertEquals(
200                 "Test11: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).getMaximumFractionDigits() returned wrong value",
201                 0, format.getMaximumFractionDigits());
202         assertTrue(
203                 "Test12: NumberFormat.getIntegerInstance(new Locale(\"de\", \"CH\")).isParseIntegerOnly() returned wrong value",
204                 format.isParseIntegerOnly());
205         // END android-added
206         format = (DecimalFormat) NumberFormat.getIntegerInstance(arLocale);
207         assertEquals(
208                 "Test7: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).toPattern() returned wrong pattern",
209                 "#,##0;#,##0-", format.toPattern());
210         assertEquals(
211                 "Test8: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).format(-35.76) returned wrong value",
212                 "\u0666-", format.format(-6));
213         assertEquals(
214                 "Test9: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).parse(\"-36-\") returned wrong number",
215                 new Long(-36), format.parse("36-"));
216         assertEquals(
217                 "Test10: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).parseObject(\"36-\") returned wrong number",
218                 new Long(-36), format.parseObject("36-"));
219
220         assertEquals(
221                 "Test11: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).getMaximumFractionDigits() returned wrong value",
222                 0, format.getMaximumFractionDigits());
223         assertTrue(
224                 "Test12: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).isParseIntegerOnly() returned wrong value",
225         format.isParseIntegerOnly());
226     }
227
228     /**
229      * @tests java.text.NumberFormat#getCurrency()
230      */
231     @TestTargetNew(
232         level = TestLevel.COMPLETE,
233         notes = "",
234         method = "getCurrency",
235         args = {}
236     )
237     public void test_getCurrency() {
238         // Test for method java.util.Currency getCurrency()
239
240         // a subclass that supports currency formatting
241         Currency currH = Currency.getInstance("HUF");
242         NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
243         assertSame("Returned incorrect currency", currH, format.getCurrency());
244
245         // a subclass that doesn't support currency formatting
246         ChoiceFormat cformat = new ChoiceFormat(
247                 "0#Less than one|1#one|1<Between one and two|2<Greater than two");
248         try {
249             ((NumberFormat) cformat).getCurrency();
250             fail("Expected UnsupportedOperationException");
251         } catch (UnsupportedOperationException e) {
252         }
253     }
254
255     /**
256      * @tests java.text.NumberFormat#setMaximumIntegerDigits()
257      */
258     @TestTargetNew(
259         level = TestLevel.COMPLETE,
260         notes = "",
261         method = "setMaximumIntegerDigits",
262         args = {int.class}
263     )
264     public void test_setMaximumIntegerDigits() {
265         NumberFormat format = NumberFormat.getInstance();
266         format.setMaximumIntegerDigits(2);
267         assertEquals("Wrong result: case 1", "23", format.format(123));
268
269         format.setMaximumIntegerDigits(Integer.MIN_VALUE);
270         assertEquals("Wrong result: case 2", "0", format.format(123));
271     }
272
273     /**
274      * @tests java.text.NumberFormat#setCurrency(java.util.Currency)
275      */
276     @TestTargetNew(
277         level = TestLevel.COMPLETE,
278         notes = "",
279         method = "setCurrency",
280         args = {java.util.Currency.class}
281     )
282     public void test_setCurrencyLjava_util_Currency() {
283         // Test for method void setCurrency(java.util.Currency)
284         // a subclass that supports currency formatting
285         Currency currA = Currency.getInstance("ARS");
286         NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
287         format.setCurrency(currA);
288         assertSame("Returned incorrect currency", currA, format.getCurrency());
289
290         // a subclass that doesn't support currency formatting
291         ChoiceFormat cformat = new ChoiceFormat(
292                 "0#Less than one|1#one|1<Between one and two|2<Greater than two");
293         try {
294             ((NumberFormat) cformat).setCurrency(currA);
295             fail("Expected UnsupportedOperationException");
296         } catch (UnsupportedOperationException e) {
297         }
298
299         try {
300             NumberFormat.getInstance().setCurrency(null);
301             fail("NullPointerException was thrown.");
302         } catch(NullPointerException npe) {
303             //expected
304         }
305
306         try {
307             NumberFormat.getIntegerInstance().setCurrency(null);
308             fail("NullPointerException was thrown.");
309         } catch(NullPointerException npe) {
310             //expected
311         }
312     }
313
314     /**
315      * @tests java.text.NumberFormat#parseObject(java.lang.String,
316      *        java.text.ParsePosition)
317      */
318     @TestTargetNew(
319         level = TestLevel.COMPLETE,
320         notes = "",
321         method = "parseObject",
322         args = {java.lang.String.class, java.text.ParsePosition.class}
323     )
324     public void test_parseObjectLjava_lang_StringLjava_text_ParsePosition() {
325         Locale[] requiredLocales = {Locale.FRANCE};
326         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
327             // locale dependent test, bug 1943269
328             return;
329         }
330         // regression test for HARMONY-1003
331         assertNull(NumberFormat.getInstance().parseObject("0",
332                 new ParsePosition(-1)));
333
334         parseObjectTest(NumberFormat.getInstance(), "123.123",
335                 new ParsePosition(1), new Double(23.123), 7, true);
336
337         parseObjectTest(NumberFormat.getInstance(), "123.123abc123",
338                 new ParsePosition(3), new Double(0.123), 7, true);
339
340         parseObjectTest(NumberFormat.getInstance(Locale.FRANCE),
341                 "asd123,123abc123",
342                 new ParsePosition(3), new Double(123.123), 10, true);
343
344         parseObjectTest(NumberFormat.getInstance(Locale.FRANCE),
345                 "test test",
346                 new ParsePosition(0), null, 0, false);
347
348         parseObjectTest(NumberFormat.getIntegerInstance(),
349                 "asd123.123abc123",
350                 new ParsePosition(3), new Long(123), 6, true);
351
352         parseObjectTest(NumberFormat.getNumberInstance(),
353                 "$-123,123.123#",
354                 new ParsePosition(1), new Double(-123123.123), 13, true);
355         parseObjectTest(NumberFormat.getNumberInstance(),
356                 "$-123,123.123#",
357                 new ParsePosition(0), null, 0, false);
358         parseObjectTest(NumberFormat.getNumberInstance(),
359                 "$-123,123.123#",
360                 new ParsePosition(13), null, 13, false);
361         parseObjectTest(NumberFormat.getPercentInstance(),
362                 "%20.123#",
363                 new ParsePosition(0), new Double(20.123), 0, false);
364         parseObjectTest(NumberFormat.getPercentInstance(),
365                 "%-200,123.123#",
366                 new ParsePosition(0), null, 0, false);
367
368
369         // Regression for HARMONY-1685
370         try {
371             NumberFormat.getInstance().parseObject("test", null);
372             fail("NullPointerException expected");
373         } catch (NullPointerException e) {
374             // expected
375         }
376     }
377
378     void parseObjectTest(NumberFormat nf, String sourseStr, ParsePosition position,
379             Object resultObj, int outIndex, boolean isSuccess) {
380         int indexBefore = position.getIndex();
381         Object result = nf.parseObject(sourseStr, position);
382         if(isSuccess) {
383             assertEquals(resultObj, result);
384             assertEquals(outIndex, position.getIndex());
385         } else {
386             assertNull(result);
387             assertEquals(indexBefore, position.getIndex());
388             assertEquals(outIndex, position.getErrorIndex());
389         }
390     }
391
392     /**
393      * @tests java.text.NumberFormat#clone()
394      */
395     @TestTargetNew(
396         level = TestLevel.COMPLETE,
397         notes = "",
398         method = "clone",
399         args = {}
400     )
401     public void test_clone() {
402
403         int max_digits = 100;
404         NumberFormat nf1 = NumberFormat.getInstance();
405         nf1.setMaximumIntegerDigits(max_digits);
406
407         NumberFormat nf2 = (NumberFormat) nf1.clone();
408         NumberFormat nf3 = (NumberFormat) nf1.clone();
409
410         assertTrue("Clonned object is not equal to object", nf2.equals(nf1));
411         assertTrue("Two clonned objects are not equal", nf2.equals(nf3));
412
413         assertTrue("Max digits value is incorrect for clonned object", nf2
414                 .getMaximumIntegerDigits() == max_digits);
415
416         nf1.setMaximumIntegerDigits(10);
417         assertTrue(
418                 "Max digits value is incorrect for clonned object after changing this value for object",
419                 nf2.getMaximumIntegerDigits() == max_digits);
420     }
421
422     /**
423      * @tests java.text.NumberFormat#equals(Object)
424      */
425     @TestTargetNew(
426         level = TestLevel.COMPLETE,
427         notes = "",
428         method = "equals",
429         args = {java.lang.Object.class}
430     )
431     public void test_equals() {
432
433         NumberFormat nf1 = NumberFormat.getInstance();
434         NumberFormat nf2 = NumberFormat.getInstance();
435
436         assertTrue("Objects are not equal", nf1.equals(nf2));
437         assertTrue("THe same Objects are not equal", nf1.equals(nf1));
438
439         nf2.setMaximumIntegerDigits(100);
440         assertFalse("Different NumberFormat are equal", nf1.equals(nf2));
441
442         nf2.setMaximumIntegerDigits(nf1.getMaximumIntegerDigits());
443         assertTrue("THe same Objects are not equal", nf1.equals(nf2));
444
445         nf1 = NumberFormat.getIntegerInstance();
446         nf2 = NumberFormat.getIntegerInstance(Locale.CHINA);
447         assertFalse("Different NumberFormat are equal", nf1.equals(nf2));
448
449         assertFalse("Object is equal null", nf1.equals(null));
450     }
451
452     /**
453      * @tests java.text.NumberFormat#format(double)
454      */
455     @TestTargetNew(
456         level = TestLevel.COMPLETE,
457         notes = "",
458         method = "format",
459         args = {double.class}
460     )
461     public void test_formatLdouble() {
462         Locale deLocale = new Locale("de", "CH");
463         Locale[] requiredLocales = {Locale.US, deLocale};
464         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
465             // locale dependent test, bug 1943269
466             return;
467         }
468         // BEGIN android-changed
469         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
470         // use de_CH instead
471         // NumberFormat nf2 = NumberFormat.getInstance(new Locale("ar", "AR"));
472         NumberFormat nf2 = NumberFormat.getInstance(deLocale);
473
474         String out = nf1.format(1234567890.0123456789);
475         assertEquals("Wrong result for double : " + out, "1,234,567,890.012",
476                 out.toString());
477
478         out = nf1.format(-1234567890.0123456789);
479         assertEquals("Wrong result for double : " + out, "-1,234,567,890.012",
480                 out.toString());
481
482         out = nf2.format(-1234567890.0123456789);
483         // use de_CH instead
484         // assertEquals("Wrong result for double : " + out, "1,234,567,890.012-",
485         //         out.toString());
486         assertEquals("Wrong result for double : " + out, "-1'234'567'890.012",
487                 out.toString());
488
489         out = nf1.format(1.0001);
490         assertEquals("Wrong result for for double: " + out, "1", out.toString());
491
492         out = nf1.format(5.0);
493         assertEquals("Wrong result for for double: " + out, "5", out.toString());
494         // END android-changed
495     }
496
497     /**
498      * @tests java.text.NumberFormat#format(long)
499      */
500     @TestTargetNew(
501         level = TestLevel.COMPLETE,
502         notes = "",
503         method = "format",
504         args = {long.class}
505     )
506     public void test_formatLlong() {
507         Locale deLocale = new Locale("de", "CH");
508         Locale[] requiredLocales = {Locale.US, deLocale};
509         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
510             // locale dependent test, bug 1943269
511             return;
512         }
513         // BEGIN android-changed
514         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
515         // use de_CH instead
516         // NumberFormat nf2 = NumberFormat.getInstance(Locale.CANADA_FRENCH);
517         NumberFormat nf2 = NumberFormat.getInstance(deLocale);
518
519         String out = nf1.format(Long.MAX_VALUE);
520         assertEquals("Wrong result for double : " + out,
521                 "9,223,372,036,854,775,807", out.toString());
522
523         out = nf1.format(Long.MIN_VALUE);
524         assertEquals("Wrong result for double : " + out,
525                 "-9,223,372,036,854,775,808", out.toString());
526
527         out = nf2.format(-1234567890);
528         // use de_CH instead
529         // assertEquals("Wrong result for double : " + out, "-1 234 567 890", out
530         //         .toString());
531         assertEquals("Wrong result for double : " + out, "-1'234'567'890", out
532                 .toString());
533
534         // the Locale data of icu uses \uc2a0
535         out = nf1.format(1);
536         assertEquals("Wrong result for for double: " + out, "1", out.toString());
537
538         out = nf1.format(0);
539         assertEquals("Wrong result for for double: " + out, "0", out.toString());
540         // END android-changed
541     }
542
543     /**
544      * @tests java.text.NumberFormat#getAvailableLocales()
545      */
546     @TestTargetNew(
547         level = TestLevel.COMPLETE,
548         notes = "",
549         method = "getAvailableLocales",
550         args = {}
551     )
552     public void test_getAvailableLocales() {
553
554         Locale[] l = NumberFormat.getAvailableLocales();
555         assertFalse("returned Locale array is null", l == null);
556         assertTrue("returned Locale length <= 0", l.length > 0);
557         Locale[] resl = Locale.getAvailableLocales();
558         assertTrue("returned Locale arrays are different",
559                 l.length == resl.length);
560         boolean isUS = false;
561         for (int i = 0; i < resl.length; i++) {
562             assertEquals("elements " + i + " are not equal: ", resl[i], l[i]);
563             if (l[i].equals(Locale.US))
564                 isUS = true;
565         }
566         assertTrue("there is no Locale.US", isUS);
567     }
568
569     /**
570      * @tests java.text.NumberFormat#getCurrencyInstance()
571      */
572     @TestTargetNew(
573         level = TestLevel.COMPLETE,
574         notes = "",
575         method = "getCurrencyInstance",
576         args = {}
577     )
578     public void test_getCurrencyInstance() {
579
580         Locale.setDefault(Locale.US);
581         NumberFormat format = NumberFormat.getCurrencyInstance();
582
583         assertNotSame("Instance is null", null, format);
584         assertTrue("Object is not instance of NumberFormat",
585                 format instanceof NumberFormat);
586
587         assertEquals(
588                 "Test1: NumberFormat.getCurrencyInstance().format(35.76) returned wrong value",
589                 "$35.76", format.format(35.76));
590         assertEquals(
591                 "Test2: NumberFormat.getCurrencyInstance().format(123456.789) returned wrong value",
592                 "$123,456.79", format.format(123456.789));
593         assertEquals(
594                 "Test3: NumberFormat.getCurrencyInstance().format(0.1) returned wrong value",
595                 "$0.10", format.format(0.1));
596         assertEquals(
597                 "Test4: NumberFormat.getCurrencyInstance().format(0.999) returned wrong value",
598                 "$1.00", format.format(0.999));
599     }
600
601     /**
602      * @tests java.text.NumberFormat#getCurrencyInstance(java.util.Locale)
603      */
604     @TestTargetNew(
605         level = TestLevel.COMPLETE,
606         notes = "",
607         method = "getCurrencyInstance",
608         args = {java.util.Locale.class}
609     )
610     public void test_getCurrencyInstanceLjava_util_Locale() {
611         // BEGIN android-changed
612         Locale usLocale = Locale.US;
613         // use de_AT instead
614         // Locale mkLocale = new Locale("mk", "MK");
615         Locale atLocale = new Locale("de", "AT");
616
617         Locale[] requiredLocales = {usLocale, atLocale};
618         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
619             // locale dependent test, bug 1943269
620             return;
621         }
622
623         NumberFormat format = NumberFormat.getCurrencyInstance(usLocale);
624
625         assertNotSame("Instance is null", null, format);
626         assertTrue("Object is not instance of NumberFormat",
627                 format instanceof NumberFormat);
628
629         assertEquals(
630                 "Test1: NumberFormat.getCurrencyInstance(Locale.US).format(35.76) returned wrong value",
631                 "$35.76", format.format(35.76));
632         assertEquals(
633                 "Test2: NumberFormat.getCurrencyInstance(Locale.US).format(123456.789) returned wrong value",
634                 "$123,456.79", format.format(123456.789));
635         assertEquals(
636                 "Test3: NumberFormat.getCurrencyInstance(Locale.US).format(0.1) returned wrong value",
637                 "$0.10", format.format(0.1));
638         assertEquals(
639                 "Test4: NumberFormat.getCurrencyInstance(Locale.US).format(0.999) returned wrong value",
640                 "$1.00", format.format(0.999));
641
642         // use de_AT instead
643         // format = NumberFormat.getCurrencyInstance(mkLocale);
644         format = NumberFormat.getCurrencyInstance(atLocale);
645         // BEGIN android-changed: ICU uses non-breaking space after the euro sign; the RI uses ' '.
646         assertEquals(
647                 "Test5: NumberFormat.getCurrencyInstance(new Locale(\"de\", \"AT\")).format(35.76) returned wrong value",
648                 "\u20ac\u00a035,76", format.format(35.76));
649         assertEquals(
650                 "Test6: NumberFormat.getCurrencyInstance(new Locale(\"de\", \"AT\")).format(123456.789) returned wrong value",
651                 "\u20ac\u00a0123.456,79", format.format(123456.789));
652         assertEquals(
653                 "Test7: NumberFormat.getCurrencyInstance(new Locale(\"de\", \"AT\")).format(0.1) returned wrong value",
654                 "\u20ac\u00a00,10", format.format(0.1));
655         assertEquals(
656                 "Test8: NumberFormat.getCurrencyInstance(new Locale(\"de\", \"AT\")).format(0.999) returned wrong value",
657                 "\u20ac\u00a01,00", format.format(0.999));
658         // END android-changed
659         // use de_AT instead
660         /*assertEquals(
661                 "Test5: NumberFormat.getCurrencyInstance(new Locale(\"mk\", \"MK\")).format(35.76) returned wrong value",
662                 "Den 35,76", format.format(35.76));
663         assertEquals(
664                 "Test6: NumberFormat.getCurrencyInstance(new Locale(\"mk\", \"MK\")).format(123456.789) returned wrong value",
665                 "Den 123.456,79", format.format(123456.789));
666         assertEquals(
667                 "Test7: NumberFormat.getCurrencyInstance(new Locale(\"mk\", \"MK\")).format(0.1) returned wrong value",
668                 "Den 0,1", format.format(0.1));
669         assertEquals(
670                 "Test8: NumberFormat.getCurrencyInstance(new Locale(\"mk\", \"MK\")).format(0.999) returned wrong value",
671                 "Den 1", format.format(0.999));*/
672         try {
673             NumberFormat.getCurrencyInstance(null);
674             fail("java.lang.NullPointerException is not thrown");
675         } catch (java.lang.NullPointerException npe) {
676             // expested
677         }
678         // END android-changed
679     }
680
681     /**
682      * @tests java.text.NumberFormat#getInstance()
683      */
684     @TestTargetNew(
685         level = TestLevel.COMPLETE,
686         notes = "",
687         method = "getInstance",
688         args = {}
689     )
690     public void test_getInstance() {
691         Locale.setDefault(Locale.US);
692         NumberFormat format = NumberFormat.getInstance();
693
694         assertNotSame("Instance is null", null, format);
695         assertTrue("Object is not instance of NumberFormat",
696                 format instanceof NumberFormat);
697
698         assertEquals(
699                 "Test1: NumberFormat.getInstance().format(1234567890.0987654321) returned wrong value",
700                 "1,234,567,890.099", format.format(1234567890.0987654321));
701         assertEquals(
702                 "Test2: ((DecimalFormat) NumberFormat.getInstance()).toPattern returned wrong value",
703                 "#,##0.###", ((DecimalFormat) format).toPattern());
704         assertEquals(
705                 "Test3: NumberFormat.getInstance().format(123456789) returned wrong value",
706                 "123,456,789", format.format(123456789));
707     }
708
709     /**
710      * @tests java.text.NumberFormat#getInstance(Locale)
711      */
712     @TestTargetNew(
713         level = TestLevel.COMPLETE,
714         notes = "",
715         method = "getInstance",
716         args = {java.util.Locale.class}
717     )
718     public void test_getInstanceLjava_util_Locale() {
719         Locale testLocale = new Locale("de", "CH");
720         Locale[] requiredLocales = {Locale.US, testLocale};
721         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
722             // locale dependent test, bug 1943269
723             return;
724         }
725         // BEGIN android-changed
726         Locale.setDefault(Locale.US);
727         // use de_CH instead
728         // NumberFormat format = NumberFormat.getInstance(new Locale("ar", "AR"));
729         NumberFormat format = NumberFormat.getInstance(testLocale);
730
731         assertNotSame("Instance is null", null, format);
732         assertTrue("Object is not instance of NumberFormat",
733                 format instanceof NumberFormat);
734
735         assertEquals(
736                 "Test1: NumberFormat.getInstance().format(1234567890.0987654321) returned wrong value",
737                 "1'234'567'890.099", format.format(1234567890.0987654321));
738         assertEquals(
739                 "Test2: ((DecimalFormat) NumberFormat.getInstance()).toPattern returned wrong value",
740                 "#,##0.###", ((DecimalFormat) format).toPattern());
741         assertEquals(
742                 "Test3: NumberFormat.getInstance().format(123456789) returned wrong value",
743                 "123'456'789", format.format(123456789));
744         // use de_CH instead
745         /*assertEquals(
746                 "Test1: NumberFormat.getInstance().format(1234567890.0987654321) returned wrong value",
747                 "1,234,567,890.099", format.format(1234567890.0987654321));
748         assertEquals(
749                 "Test2: ((DecimalFormat) NumberFormat.getInstance()).toPattern returned wrong value",
750                 "#,##0.###;#,##0.###-", ((DecimalFormat) format).toPattern());
751         assertEquals(
752                 "Test3: NumberFormat.getInstance().format(123456789) returned wrong value",
753                 "123,456,789", format.format(123456789));*/
754         try {
755             NumberFormat.getInstance(null);
756             fail("java.lang.NullPointerException is not thrown");
757         } catch (java.lang.NullPointerException npe) {
758             // expested
759         }
760         // END android-changed
761     }
762
763     /**
764      * @tests java.text.NumberFormat#getNumberInstance()
765      */
766     @TestTargetNew(
767         level = TestLevel.COMPLETE,
768         notes = "",
769         method = "getNumberInstance",
770         args = {}
771     )
772     public void test_getNumberInstance() {
773         Locale.setDefault(Locale.US);
774         NumberFormat format = NumberFormat.getNumberInstance();
775
776         assertNotSame("Instance is null", null, format);
777         assertTrue("Object is not instance of NumberFormat",
778                 format instanceof NumberFormat);
779
780         assertEquals(
781                 "Test1: NumberFormat.getNumberInstance().format(1234567890.0987654321) returned wrong value",
782                 "1,234,567,890.099", format.format(1234567890.0987654321));
783         assertEquals(
784                 "Test2: ((DecimalFormat) NumberFormat.getNumberInstance()).toPattern returned wrong value",
785                 "#,##0.###", ((DecimalFormat) format).toPattern());
786         assertEquals(
787                 "Test3: NumberFormat.getNumberInstance().format(123456789) returned wrong value",
788                 "123,456,789", format.format(123456789));
789     }
790
791     /**
792      * @tests java.text.NumberFormat#getNumberInstance(Locale)
793      */
794     @TestTargetNew(
795         level = TestLevel.COMPLETE,
796         notes = "",
797         method = "getNumberInstance",
798         args = {java.util.Locale.class}
799     )
800     public void test_getNumberInstanceLjava_util_Locale() {
801         Locale deLocale = new Locale("de", "CH");
802         Locale[] requiredLocales = {Locale.US, deLocale};
803         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
804             // locale dependent test, bug 1943269
805             return;
806         }
807         // BEGIN android-changed
808         Locale.setDefault(Locale.US);
809         // use de_CH instead
810         NumberFormat format = NumberFormat.getNumberInstance(deLocale);
811         // NumberFormat format = NumberFormat.getNumberInstance(new Locale("ar",
812         //         "AR"));
813
814         assertNotSame("Instance is null", null, format);
815         assertTrue("Object is not instance of NumberFormat",
816                 format instanceof NumberFormat);
817
818         assertEquals(
819                 "Test1: NumberFormat.getNumberInstance().format(-1234567890.0987654321) returned wrong value",
820                 "-1'234'567'890.099", format.format(-1234567890.0987654321));
821         assertEquals(
822                 "Test2: ((DecimalFormat) NumberFormat.getNumberInstance()).toPattern returned wrong value",
823                 "#,##0.###", ((DecimalFormat) format).toPattern());
824         assertEquals(
825                 "Test3: NumberFormat.getNumberInstance().format(123456789) returned wrong value",
826                 "123'456'789", format.format(123456789));
827         // use de_CH instead
828         /*assertEquals(
829                 "Test1: NumberFormat.getNumberInstance().format(-1234567890.0987654321) returned wrong value",
830                 "1,234,567,890.099-", format.format(-1234567890.0987654321));
831         assertEquals(
832                 "Test2: ((DecimalFormat) NumberFormat.getNumberInstance()).toPattern returned wrong value",
833                 "#,##0.###;#,##0.###-", ((DecimalFormat) format).toPattern());
834         assertEquals(
835                 "Test3: NumberFormat.getNumberInstance().format(123456789) returned wrong value",
836                 "123,456,789", format.format(123456789));*/
837         try {
838             NumberFormat.getInstance(null);
839             fail("java.lang.NullPointerException is not thrown");
840         } catch (java.lang.NullPointerException npe) {
841             // expested
842         }
843         // END android-changed
844     }
845
846     /**
847      * @tests java.text.NumberFormat#getPercentInstance()
848      */
849     @TestTargetNew(
850         level = TestLevel.COMPLETE,
851         notes = "",
852         method = "getPercentInstance",
853         args = {}
854     )
855     public void test_getPercentInstance() {
856         Locale.setDefault(Locale.US);
857         NumberFormat format = NumberFormat.getPercentInstance();
858
859         assertNotSame("Instance is null", null, format);
860         assertTrue("Object is not instance of NumberFormat",
861                 format instanceof NumberFormat);
862
863         assertEquals(
864                 "Test1: NumberFormat.getPercentInstance().format(1234567890.0987654321) returned wrong value",
865                 "123,456,789,010%", format.format(1234567890.0987654321));
866         assertEquals(
867                 "Test2: ((DecimalFormat) NumberFormat.getPercentInstance()).toPattern returned wrong value",
868                 "#,##0%", ((DecimalFormat) format).toPattern());
869         assertEquals(
870                 "Test3: NumberFormat.getPercentInstance().format(123456789) returned wrong value",
871                 "12,345,678,900%", format.format(123456789));
872     }
873
874     /**
875      * @tests java.text.NumberFormat#getPercentInstance(Locale)
876      */
877     @TestTargetNew(
878         level = TestLevel.COMPLETE,
879         notes = "",
880         method = "getPercentInstance",
881         args = {java.util.Locale.class}
882     )
883     public void test_getPercentInstanceLjava_util_Locale() {
884         Locale csLocale = new Locale("cs", "CZ");
885         Locale[] requiredLocales = {Locale.US, csLocale};
886         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
887             // locale dependent test, bug 1943269
888             return;
889         }
890         Locale.setDefault(Locale.US);
891         NumberFormat format = NumberFormat.getPercentInstance(csLocale);
892
893         assertNotSame("Instance is null", null, format);
894         assertTrue("Object is not instance of NumberFormat",
895                 format instanceof NumberFormat);
896
897         assertEquals(
898                 "Test1: NumberFormat.getPercentInstance().format(1234567890.0987654321) returned wrong value",
899                 "123\u00a0456\u00a0789\u00a0010%", format.format(1234567890.0987654321));
900         assertEquals(
901                 "Test2: ((DecimalFormat) NumberFormat.getPercentInstance()).toPattern returned wrong value",
902                 "#,##0%", ((DecimalFormat) format).toPattern());
903         assertEquals(
904                 "Test3: NumberFormat.getPercentInstance().format(123456789) returned wrong value",
905                 "12\u00a0345\u00a0678\u00a0900%", format.format(123456789));
906         try {
907             NumberFormat.getInstance(null);
908             fail("java.lang.NullPointerException is not thrown");
909         } catch (java.lang.NullPointerException npe) {
910             // expested
911         }
912     }
913
914     /**
915      * @tests java.text.NumberFormat#getMaximumFractionDigits()
916      */
917     @TestTargetNew(
918         level = TestLevel.COMPLETE,
919         notes = "",
920         method = "getMaximumFractionDigits",
921         args = {}
922     )
923     public void test_getMaximumFractionDigits() {
924         NumberFormat nf1 = NumberFormat.getInstance();
925
926         nf1.setMaximumFractionDigits(Integer.MAX_VALUE);
927         int result = nf1.getMaximumFractionDigits();
928         assertTrue("getMaximumFractionDigits returns " + result
929                 + " instead of: " + Integer.MAX_VALUE,
930                 result == Integer.MAX_VALUE);
931
932         nf1.setMaximumFractionDigits(0);
933         result = nf1.getMaximumFractionDigits();
934         assertTrue("getMaximumFractionDigits returns " + result
935                 + " instead of 0", result == 0);
936
937         nf1.setMinimumFractionDigits(Integer.MAX_VALUE);
938         result = nf1.getMaximumFractionDigits();
939         assertTrue("getMaximumFractionDigits returns " + result
940                 + " instead of Integer.MAX_VALUE", result == Integer.MAX_VALUE);
941     }
942
943     /**
944      * @tests java.text.NumberFormat#getMinimumFractionDigits()
945      */
946     @TestTargetNew(
947         level = TestLevel.COMPLETE,
948         notes = "",
949         method = "getMinimumFractionDigits",
950         args = {}
951     )
952     public void test_getMinimumFractionDigits() {
953         NumberFormat nf1 = NumberFormat.getInstance();
954         nf1.setMinimumFractionDigits(Integer.MAX_VALUE);
955         int result = nf1.getMinimumFractionDigits();
956         assertTrue("getMinimumFractionDigits returns " + result
957                 + " instead of: " + Integer.MAX_VALUE,
958                 result == Integer.MAX_VALUE);
959
960         nf1.setMaximumFractionDigits(0);
961         result = nf1.getMinimumFractionDigits();
962         assertTrue("getMinimumFractionDigits returns " + result
963                 + " instead of 0", result == 0);
964
965         nf1.setMinimumFractionDigits(52);
966         result = nf1.getMinimumFractionDigits();
967         assertTrue("getMinimumFractionDigits returns " + result
968                 + " instead of 52", result == 52);
969     }
970
971     /**
972      * @tests java.text.NumberFormat#getMaximumIntegerDigits()
973      */
974     @TestTargetNew(
975         level = TestLevel.COMPLETE,
976         notes = "",
977         method = "getMaximumIntegerDigits",
978         args = {}
979     )
980     public void test_getMaximumIntegerDigits() {
981         NumberFormat nf1 = NumberFormat.getInstance();
982         nf1.setMaximumIntegerDigits(Integer.MAX_VALUE);
983         int result = nf1.getMaximumIntegerDigits();
984         assertTrue("getMaximumIntegerDigits returns " + result
985                 + " instead of: " + Integer.MAX_VALUE,
986                 result == Integer.MAX_VALUE);
987
988         nf1.setMaximumIntegerDigits(0);
989         result = nf1.getMaximumIntegerDigits();
990         assertTrue("getMaximumIntegerDigits returns " + result
991                 + " instead of 0", result == 0);
992
993         nf1.setMinimumIntegerDigits(Integer.MAX_VALUE);
994         result = nf1.getMaximumIntegerDigits();
995         assertTrue("getMaximumIntegerigits returns " + result
996                 + " instead of Integer.MAX_VALUE", result == Integer.MAX_VALUE);
997     }
998
999     /**
1000      * @tests java.text.NumberFormat#getMinimumIntegerDigits()
1001      */
1002     @TestTargetNew(
1003         level = TestLevel.COMPLETE,
1004         notes = "",
1005         method = "getMinimumIntegerDigits",
1006         args = {}
1007     )
1008     public void test_getMinimumIntegernDigits() {
1009         NumberFormat nf1 = NumberFormat.getInstance();
1010         nf1.setMinimumIntegerDigits(Integer.MAX_VALUE);
1011         int result = nf1.getMinimumIntegerDigits();
1012         assertTrue("getMinimumIntegerDigits returns " + result
1013                 + " instead of: " + Integer.MAX_VALUE,
1014                 result == Integer.MAX_VALUE);
1015
1016         nf1.setMaximumIntegerDigits(0);
1017         result = nf1.getMinimumIntegerDigits();
1018         assertTrue("getMinimumIntegerDigits returns " + result
1019                 + " instead of 0", result == 0);
1020
1021         nf1.setMinimumIntegerDigits(0x12034);
1022         result = nf1.getMinimumIntegerDigits();
1023         assertTrue("getMinimumIntegerDigits returns " + result
1024                 + " instead of 5148", result == 73780);
1025     }
1026
1027     /**
1028      * @tests java.text.NumberFormat#hashCode()
1029      */
1030     @TestTargetNew(
1031         level = TestLevel.COMPLETE,
1032         notes = "",
1033         method = "hashCode",
1034         args = {}
1035     )
1036     public void test_hashCode() {
1037
1038         NumberFormat nf1 = NumberFormat.getInstance();
1039         NumberFormat nf11 = NumberFormat.getInstance();
1040         NumberFormat nf2 = NumberFormat.getInstance(Locale.US);
1041         NumberFormat nf3 = NumberFormat.getPercentInstance();
1042         NumberFormat nf4 = NumberFormat.getCurrencyInstance();
1043         NumberFormat nf5 = NumberFormat
1044                 .getNumberInstance(new Locale("mk", "MK"));
1045         NumberFormat nf6 = NumberFormat.getInstance(Locale.US);
1046
1047         assertTrue("Hash codes are not equal: case 1", nf1.hashCode() == nf2
1048                 .hashCode());
1049         assertTrue("Hash codes are not equal: case 2", nf1.hashCode() == nf11
1050                 .hashCode());
1051         assertTrue("Hash codes are not equal: case 3", nf1.hashCode() == nf3
1052                 .hashCode());
1053         assertFalse("Hash codes are equal: case 4", nf3.hashCode() == nf4
1054                 .hashCode());
1055         assertFalse("Hash codes are equal: case 5", nf4.hashCode() == nf5
1056                 .hashCode());
1057         assertTrue("Hash codes are not equal: case 6", nf5.hashCode() == nf6
1058                 .hashCode());
1059
1060         nf1.setMaximumFractionDigits(0);
1061         assertTrue("Hash codes are not equal: case 7", nf1.hashCode() == nf11
1062                 .hashCode());
1063     }
1064
1065     /**
1066      * @tests java.text.NumberFormat#isGroupingUsed()
1067      */
1068     @TestTargetNew(
1069         level = TestLevel.COMPLETE,
1070         notes = "",
1071         method = "isGroupingUsed",
1072         args = {}
1073     )
1074     public void test_isGroupingUsed() {
1075         NumberFormat nf1 = NumberFormat.getInstance();
1076         assertTrue("grouping is not used for NumberFormat.getInstance", nf1
1077                 .isGroupingUsed());
1078
1079         nf1.setGroupingUsed(false);
1080         assertFalse(
1081                 "grouping is used for NumberFormat.getInstance after setting false",
1082                 nf1.isGroupingUsed());
1083
1084         nf1.setGroupingUsed(true);
1085         assertTrue(
1086                 "grouping is not used for NumberFormat.getInstance after setting true",
1087                 nf1.isGroupingUsed());
1088     }
1089
1090     /**
1091      * @tests java.text.NumberFormat#setGroupingUsed(boolean)
1092      */
1093     @TestTargetNew(
1094         level = TestLevel.COMPLETE,
1095         notes = "",
1096         method = "setGroupingUsed",
1097         args = {boolean.class}
1098     )
1099     public void test_setGroupingUsed() {
1100         Locale csLocale = new Locale("cs", "CZ");
1101         Locale[] requiredLocales = {Locale.US, csLocale};
1102         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
1103             // locale dependent test, bug 1943269
1104             return;
1105         }
1106         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
1107         nf1.setGroupingUsed(false);
1108
1109         assertEquals("grouping is used for 1234567890.1", "1234567890.1",
1110                 nf1.format(1234567890.1));
1111
1112         assertEquals("grouping is used for -1234567890.1", "-1234567890.1",
1113                 nf1.format(-1234567890.1));
1114
1115         nf1.setGroupingUsed(false);
1116
1117         assertEquals("grouping is used for 1234567890.1", "1234567890.1",
1118                 nf1.format(1234567890.1));
1119
1120         assertEquals("grouping is used for -1234567890.1", "-1234567890.1",
1121                 nf1.format(-1234567890.1));
1122
1123         nf1.setGroupingUsed(true);
1124
1125         assertEquals("grouping is not used for 1234567890.1",
1126                 "1,234,567,890.1", nf1.format(1234567890.1));
1127
1128         assertEquals("grouping is not used for -1234567890.1",
1129                 "-1,234,567,890.1", nf1.format(-1234567890.1));
1130
1131         NumberFormat nf2 = NumberFormat.getPercentInstance(csLocale);
1132         nf2.setGroupingUsed(false);
1133         assertEquals(
1134                 "Locale(\"cs\", \"CZ\"): grouping is used for 1234567890.1",
1135                 "123456789010%", nf2.format(1234567890.1));
1136
1137         assertEquals(
1138                 "Locale(\"cs\", \"CZ\"): grouping is used for -1234567890.1",
1139                 "-123456789010%", nf2.format(-1234567890.1));
1140         assertEquals("grouping is not used for 1234567890.1",
1141                 "1,234,567,890.1", nf1.format(1234567890.1));
1142
1143         nf2.setGroupingUsed(true);
1144         assertEquals(
1145                 "Locale(\"cs\", \"CZ\"): grouping is not used for 1234567890.1",
1146                 "123\u00a0456\u00a0789\u00a0010%", nf2.format(1234567890.1));
1147
1148         assertEquals(
1149                 "Locale(\"cs\", \"CZ\"): grouping is not used for -1234567890.1",
1150                 "-123\u00a0456\u00a0789\u00a0010%", nf2.format(-1234567890.1));
1151
1152         nf2.setGroupingUsed(true);
1153         assertEquals(
1154                 "Locale(\"cs\", \"CZ\"): grouping is not used for 1234567890.1",
1155                 "123\u00a0456\u00a0789\u00a0010%", nf2.format(1234567890.1));
1156
1157         assertEquals(
1158                 "Locale(\"cs\", \"CZ\"): grouping is not used for -1234567890.1",
1159                 "-123\u00a0456\u00a0789\u00a0010%", nf2.format(-1234567890.1));
1160     }
1161
1162     /**
1163      * @tests java.text.NumberFormat#isParseIntegerOnly()
1164      */
1165     @TestTargetNew(
1166         level = TestLevel.COMPLETE,
1167         notes = "",
1168         method = "isParseIntegerOnly",
1169         args = {}
1170     )
1171     public void test_isParseIntegerOnly() {
1172         NumberFormat nf1 = NumberFormat.getInstance();
1173         assertTrue("ParseIntegerOnly is not used for NumberFormat.getInstance",
1174                 nf1.isGroupingUsed());
1175
1176         nf1.setParseIntegerOnly(false);
1177         assertFalse(
1178                 "ParseIntegerOnly is used for NumberFormat.getInstance after setting false",
1179                 nf1.isParseIntegerOnly());
1180
1181         nf1.setParseIntegerOnly(true);
1182         assertTrue(
1183                 "ParseIntegerOnly is not used for NumberFormat.getInstance after setting true",
1184                 nf1.isParseIntegerOnly());
1185     }
1186
1187     /**
1188      * @tests java.text.NumberFormat#setParseIntegerOnly(boolean)
1189      */
1190     @TestTargetNew(
1191         level = TestLevel.COMPLETE,
1192         notes = "",
1193         method = "setParseIntegerOnly",
1194         args = {boolean.class}
1195     )
1196     public void test_setParseIntegerOnly() {
1197         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
1198         nf1.setParseIntegerOnly(true);
1199
1200         assertEquals("ParseIntegerOnly is not used for 1234567890.1",
1201                 "1,234,567,890.1", nf1.format(1234567890.1));
1202         assertEquals("ParseIntegerOnly is not used for -1234567890.1",
1203                 "-1,234,567,890.1", nf1.format(-1234567890.1));
1204         assertEquals("ParseIntegerOnly is not used for -1234567890.",
1205                 "-1,234,567,890", nf1.format(-1234567890.));
1206
1207         nf1.setParseIntegerOnly(false);
1208
1209         assertEquals("ParseIntegerOnly is not used for 1234567890.1",
1210                 "1,234,567,890.1", nf1.format(1234567890.1));
1211         assertEquals("ParseIntegerOnly is not used for -1234567890.1",
1212                 "-1,234,567,890.1", nf1.format(-1234567890.1));
1213         assertEquals("ParseIntegerOnly is not used for -1234567890.",
1214                 "-1,234,567,890", nf1.format(-1234567890.));
1215     }
1216
1217     /**
1218      * @tests java.text.NumberFormat#setMaximumFractionDigits(int)
1219      */
1220     @TestTargetNew(
1221         level = TestLevel.COMPLETE,
1222         notes = "",
1223         method = "setMaximumFractionDigits",
1224         args = {int.class}
1225     )
1226     public void test_setMaximumFractionDigits() {
1227         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
1228         nf1.setMaximumFractionDigits(Integer.MAX_VALUE);
1229         int result = nf1.getMaximumFractionDigits();
1230         assertTrue("setMaximumFractionDigits set " + result
1231                 + " instead of Integer.MAX_VALUE", result == Integer.MAX_VALUE);
1232         nf1.setMaximumFractionDigits(0);
1233         result = nf1.getMaximumFractionDigits();
1234         assertTrue("setMaximumFractionDigits set " + result + " instead of 0",
1235                 result == 0);
1236         assertEquals("format of 1234567890.0987654321 returns incorrect value",
1237                 "1,234,567,890", nf1.format(1234567890.0987654321));
1238         nf1.setMaximumFractionDigits(5);
1239         result = nf1.getMaximumFractionDigits();
1240         assertTrue("setMaximumFractionDigits set " + result + " instead of 5",
1241                 result == 5);
1242         assertEquals(
1243                 "format of 1234567890.0987654321 returns incorrect value with MaximumFractionDigits = 5",
1244                 "1,234,567,890.09877", nf1.format(1234567890.0987654321));
1245         assertEquals(
1246                 "format of -1234567890 returns incorrect value with MaximumFractionDigits = 5",
1247                 "-1,234,567,890", nf1.format(-1234567890));
1248         nf1.setMaximumFractionDigits(Integer.MIN_VALUE);
1249         result = nf1.getMaximumFractionDigits();
1250         assertTrue("setMaximumFractionDigits set " + result
1251                 + " instead of Integer.MIN_VALUE", result == 0);
1252         assertEquals(
1253                 "format of 1234567890.0987654321 returns incorrect value with MaximumFractionDigits = 5",
1254                 "1,234,567,890", nf1.format(1234567890.0987654321));
1255     }
1256
1257     /**
1258      * @tests java.text.NumberFormat#setMinimumFractionDigits(int)
1259      */
1260     @TestTargetNew(
1261         level = TestLevel.COMPLETE,
1262         notes = "",
1263         method = "setMinimumFractionDigits",
1264         args = {int.class}
1265     )
1266     public void test_setMinimumFractionDigits() {
1267
1268         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
1269         nf1.setMinimumFractionDigits(Integer.MAX_VALUE);
1270         int result = nf1.getMinimumFractionDigits();
1271         assertTrue("setMinimumFractionDigits set " + result
1272                 + " instead of Integer.MAX_VALUE", result == Integer.MAX_VALUE);
1273         nf1.setMinimumFractionDigits(0);
1274         result = nf1.getMinimumFractionDigits();
1275         assertTrue("setMinimumFractionDigits set " + result + " instead of 0",
1276                 result == 0);
1277         nf1.setMinimumFractionDigits(5);
1278         result = nf1.getMinimumFractionDigits();
1279         assertTrue("setMinimumFractionDigits set " + result + " instead of 5",
1280                 result == 5);
1281         assertEquals(
1282                 "format of 1234567890.0987654321 returns incorrect value with MinimumFractionDigits = 5",
1283                 "1,234,567,890.09000", nf1.format(1234567890.09));
1284         assertEquals(
1285                 "format of -1234567890 returns incorrect value with MinimumFractionDigits = 5",
1286                 "-1,234,567,890.00000", nf1.format(-1234567890));
1287         nf1.setMinimumFractionDigits(Integer.MIN_VALUE);
1288         result = nf1.getMinimumFractionDigits();
1289         assertTrue("setMinimumFractionDigits set " + result
1290                 + " instead of Integer.MIN_VALUE", result == 0);
1291         assertEquals(
1292                 "format of 1234567890.098 returns incorrect value with MinimumFractionDigits = 5",
1293                 "1,234,567,890.098", nf1.format(1234567890.098));
1294     }
1295
1296     /**
1297      * @tests java.text.NumberFormat#setMinimumIntegerDigits(int)
1298      */
1299     @TestTargetNew(
1300         level = TestLevel.COMPLETE,
1301         notes = "",
1302         method = "setMinimumIntegerDigits",
1303         args = {int.class}
1304     )
1305     public void test_setMinimumIntegerDigits() {
1306
1307         NumberFormat nf1 = NumberFormat.getInstance(Locale.US);
1308         nf1.setMinimumIntegerDigits(Integer.MAX_VALUE);
1309         int result = nf1.getMinimumIntegerDigits();
1310         assertTrue("setMinimumIntegerDigits set " + result
1311                 + " instead of Integer.MAX_VALUE", result == Integer.MAX_VALUE);
1312         nf1.setMinimumIntegerDigits(0);
1313         result = nf1.getMinimumIntegerDigits();
1314         assertTrue("setMinimumIntegerDigits set " + result + " instead of 0",
1315                 result == 0);
1316         nf1.setMinimumIntegerDigits(5);
1317         result = nf1.getMinimumIntegerDigits();
1318         assertTrue("setMinimumIntegerDigits set " + result + " instead of 5",
1319                 result == 5);
1320         assertEquals(
1321                 "format of 123.09 returns incorrect value with MinimumIntegerDigits = 5",
1322                 "00,123.09", nf1.format(123.09));
1323         assertEquals(
1324                 "format of -123 returns incorrect value with MinimumIntegerDigits = 5",
1325                 "-00,123", nf1.format(-123));
1326         nf1.setMinimumIntegerDigits(Integer.MIN_VALUE);
1327         result = nf1.getMinimumIntegerDigits();
1328         assertTrue("setMinimumIntegerDigits set " + result
1329                 + " instead of Integer.MIN_VALUE", result == 0);
1330     }
1331
1332     /**
1333      * @tests java.text.NumberFormat#parse(String)
1334      */
1335     @TestTargetNew(
1336         level = TestLevel.COMPLETE,
1337         notes = "",
1338         method = "parse",
1339         args = {java.lang.String.class}
1340     )
1341     @BrokenTest("Fails in CTS, passes in CoreTestRunner")
1342     public void test_parseLjava_lang_String() {
1343         NumberFormat nf1 = NumberFormat.getInstance();
1344         try {
1345             assertEquals(
1346                     "Test1: NumberFormat.getInstance().parse(\"1234567890.1\") returned wrong number",
1347                     new Double(1234567890.1), nf1.parse("1234567890.1"));
1348         } catch (java.text.ParseException pe) {
1349             fail("java.text.ParseException is thrown for 1234567890.1");
1350         }
1351
1352         try {
1353             assertEquals(
1354                     "Test2: NumberFormat.getInstance().parse(\"-1234567890.1\") returned wrong number",
1355                     new Double(-1234567890.1), nf1.parse("-1,234,567,890.1"));
1356         } catch (java.text.ParseException pe) {
1357             fail("java.text.ParseException is thrown for -1,234,567,890.1");
1358         }
1359
1360         try {
1361             nf1.parse("@1,234,567,8901");
1362             fail("java.text.ParseException is not thrown for 1,234,567,890z1");
1363         } catch (java.text.ParseException pe) {
1364             // expected
1365         }
1366
1367         nf1 = NumberFormat.getPercentInstance();
1368         try {
1369             assertEquals(
1370                     "Test3: NumberFormat.getPercentInstance().parse(\"-123%\") returned wrong number",
1371                     new Double(-1.23), nf1.parse("-123%"));
1372         } catch (java.text.ParseException pe) {
1373             fail("java.text.ParseException is thrown for -123%");
1374         }
1375
1376         nf1 = NumberFormat.getCurrencyInstance();
1377         try {
1378             assertEquals(
1379                     "Test4: NumberFormat.getCurrencyInstance().parse(\"$123\") returned wrong number",
1380                     new Long(123), nf1.parse("$123"));
1381         } catch (java.text.ParseException pe) {
1382             fail("java.text.ParseException is thrown for $123");
1383         }
1384
1385         try {
1386             assertEquals(
1387                     "Test4: NumberFormat.getCurrencyInstance().parse(\"$123abc\") returned wrong number",
1388                     new Long(123), nf1.parse("$123abc"));
1389         } catch (java.text.ParseException pe) {
1390             fail("java.text.ParseException is thrown for $123");
1391         }
1392
1393         nf1 = NumberFormat.getIntegerInstance();
1394         try {
1395             assertEquals(
1396                     "Test5: NumberFormat.getIntegerInstance().parse(\"-123.123\") returned wrong number",
1397                     nf1.parseObject("-123.123"), nf1.parse("-123.123"));
1398         } catch (java.text.ParseException pe) {
1399             fail("java.text.ParseException is thrown for $123");
1400         }
1401     }
1402
1403     /**
1404      * @tests java.text.NumberFormat#NumberFormat()
1405      */
1406     @TestTargetNew(
1407         level = TestLevel.COMPLETE,
1408         notes = "",
1409         method = "NumberFormat",
1410         args = {}
1411     )
1412     public void test_constructor() {
1413         MyNumberFormat mf = new MyNumberFormat();
1414         assertFalse("Greated NumberFormat object is null", mf == null);
1415         assertTrue(
1416                 "Greated NumberFormat object is not instance of NumberFormat",
1417                 mf instanceof NumberFormat);
1418     }
1419
1420     class MyNumberFormat extends NumberFormat {
1421         static final long serialVersionUID = 1L;
1422
1423         public MyNumberFormat() {
1424             super();
1425         }
1426
1427         public StringBuffer format(double number, StringBuffer toAppendTo,
1428                 FieldPosition pos) {
1429
1430             return new StringBuffer();
1431         }
1432
1433         public Number parse(String source, ParsePosition parsePosition) {
1434
1435             return new Double(0);
1436         }
1437
1438         public StringBuffer format(long number, StringBuffer toAppendTo,
1439                 FieldPosition pos) {
1440             return new StringBuffer();
1441         }
1442
1443     }
1444 }