1 /*
   2  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4018937 8008577
  27  * @summary Confirm that methods which are newly added to support BigDecimal and BigInteger work as expected.
  28  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI BigDecimalFormat
  29  */
  30 
  31 import java.math.BigDecimal;
  32 import java.math.BigInteger;
  33 import java.text.DecimalFormat;
  34 import java.text.FieldPosition;
  35 import java.text.MessageFormat;
  36 import java.text.NumberFormat;
  37 import java.util.Locale;
  38 
  39 import org.junit.jupiter.api.Test;
  40 
  41 import static org.junit.jupiter.api.Assertions.fail;
  42 
  43 public class BigDecimalFormat {
  44 
  45     static final String nonsep_int =
  46         "123456789012345678901234567890123456789012345678901234567890" +
  47         "123456789012345678901234567890123456789012345678901234567890" +
  48         "123456789012345678901234567890123456789012345678901234567890" +
  49         "123456789012345678901234567890123456789012345678901234567890" +
  50         "123456789012345678901234567890123456789012345678901234567890" +
  51         "123456789012345678901234567890123456789012345678901234567890";
  52 
  53     static final String sep_int =
  54         "123,456,789,012,345,678,901,234,567,890," +
  55         "123,456,789,012,345,678,901,234,567,890," +
  56         "123,456,789,012,345,678,901,234,567,890," +
  57         "123,456,789,012,345,678,901,234,567,890," +
  58         "123,456,789,012,345,678,901,234,567,890," +
  59         "123,456,789,012,345,678,901,234,567,890," +
  60         "123,456,789,012,345,678,901,234,567,890," +
  61         "123,456,789,012,345,678,901,234,567,890," +
  62         "123,456,789,012,345,678,901,234,567,890," +
  63         "123,456,789,012,345,678,901,234,567,890," +
  64         "123,456,789,012,345,678,901,234,567,890," +
  65         "123,456,789,012,345,678,901,234,567,890";
  66 
  67     static final String nonsep_zero =
  68         "000000000000000000000000000000000000000000000000000000000000" +
  69         "000000000000000000000000000000000000000000000000000000000000" +
  70         "000000000000000000000000000000000000000000000000000000000000" +
  71         "000000000000000000000000000000000000000000000000000000000000" +
  72         "000000000000000000000000000000000000000000000000000000000000" +
  73         "000000000000000000000000000000000000000000000000000000000000";
  74 
  75     static final String sep_zero =
  76         "000,000,000,000,000,000,000,000,000,000," +
  77         "000,000,000,000,000,000,000,000,000,000," +
  78         "000,000,000,000,000,000,000,000,000,000," +
  79         "000,000,000,000,000,000,000,000,000,000," +
  80         "000,000,000,000,000,000,000,000,000,000," +
  81         "000,000,000,000,000,000,000,000,000,000," +
  82         "000,000,000,000,000,000,000,000,000,000," +
  83         "000,000,000,000,000,000,000,000,000,000," +
  84         "000,000,000,000,000,000,000,000,000,000," +
  85         "000,000,000,000,000,000,000,000,000,000," +
  86         "000,000,000,000,000,000,000,000,000,000," +
  87         "000,000,000,000,000,000,000,000,000,000";
  88 
  89     static final String fra =
  90         "012345678901234567890123456789012345678901234567890123456789" +
  91         "012345678901234567890123456789012345678901234567890123456789" +
  92         "012345678901234567890123456789012345678901234567890123456789" +
  93         "012345678901234567890123456789012345678901234567890123456789" +
  94         "012345678901234567890123456789012345678901234567890123456789" +
  95         "012345678901234567890123456789012345678901234567890123456789";
  96 
  97 
  98     StringBuffer formatted = new StringBuffer(1000);
  99     FieldPosition fp;
 100 
 101     /**
 102      * Test for normal big numbers which have the fraction part
 103      */
 104     @Test
 105     void test_Format_in_NumberFormat_BigDecimal() {
 106         String from, to;
 107 
 108         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 109         ((DecimalFormat)nf).applyPattern("#,##0.###");
 110         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 111 
 112         // From: 0.000...789
 113         // To:   0.000...789 (same as From)
 114         formatted.setLength(0);
 115         from = "0." + nonsep_zero + "123456789";
 116         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 117         checkFormat(from, formatted, from, ((DecimalFormat)nf).getMultiplier());
 118 
 119         /* ------------------------------------------------------------------ */
 120 
 121         // From: -0.000...789
 122         // To:   -0.000...789 (same as From)
 123         //       ~ : FieldPosition(SIGN)
 124         fp = new FieldPosition(NumberFormat.Field.SIGN);
 125         formatted.setLength(0);
 126         from = "-0." + nonsep_zero + "123456789";
 127         nf.format(new BigDecimal(from), formatted, fp);
 128         checkFormat(from, formatted, from, ((DecimalFormat)nf).getMultiplier());
 129         checkFieldPosition(from, fp, 0, 1);
 130 
 131         /* ------------------------------------------------------------------ */
 132 
 133         // From: 1234...7890.012...789
 134         // To:   123,4...7,890.012...789
 135         //       ~~~~~~~~~~~~~ : FieldPosition(INTEGER_FIELD)
 136         fp = new FieldPosition(DecimalFormat.INTEGER_FIELD);
 137         formatted.setLength(0);
 138         from = nonsep_int + "." + fra;
 139         to   = sep_int    + "." + fra;
 140         nf.format(new BigDecimal(from), formatted, fp);
 141         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 142         checkFieldPosition(from, fp, 0, 479);
 143 
 144         /* ------------------------------------------------------------------ */
 145 
 146         // From: -1234...7890.012...789
 147         // To:   -123,4...7,890.012...789
 148         //                    ~~~~~~~~~ : FieldPosition(FRACTION_FIELD)
 149         fp = new FieldPosition(DecimalFormat.FRACTION_FIELD);
 150         formatted.setLength(0);
 151         from = "-" + nonsep_int + "." + fra;
 152         to   = "-" + sep_int    + "." + fra;
 153         nf.format(new BigDecimal(from), formatted, fp);
 154         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 155         checkFieldPosition(from, fp, 481, 841);
 156 
 157         /* ------------------------------------------------------------------ */
 158 
 159         // From: 1234...78900000...0000.000...789
 160         // To:   123,4...7,890,000,0...0,000.000...789
 161         formatted.setLength(0);
 162         from = nonsep_int + nonsep_zero + "." + nonsep_zero + fra;
 163         to   = sep_int + "," + sep_zero + "." + nonsep_zero + fra;
 164         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 165         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 166 
 167         /* ------------------------------------------------------------------ */
 168 
 169         // From: -1234...78900000...0000.000...789
 170         // To:   -123,4...7,890,000,0...0,000.000...789
 171         formatted.setLength(0);
 172         from = "-" + nonsep_int + nonsep_zero + "." + nonsep_zero + fra;
 173         to   = "-" + sep_int + "," + sep_zero + "." + nonsep_zero + fra;
 174         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 175         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 176 
 177         /* ------------------------------------------------------------------ */
 178 
 179         // From: 1234...78900000...0000
 180         // To:   123,4...7,890,000,0...0,000
 181         formatted.setLength(0);
 182         from = nonsep_int + nonsep_zero;
 183         to   = sep_int + "," + sep_zero;
 184         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 185         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 186 
 187         /* ------------------------------------------------------------------ */
 188 
 189         // From: -1234...78900000...0000
 190         // To:   -123,4...7,890,000,0...0,000
 191         formatted.setLength(0);
 192         from = "-" + nonsep_int + nonsep_zero;
 193         to   = "-" + sep_int + "," + sep_zero;
 194         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 195         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 196 
 197         /* ------------------------------------------------------------------ */
 198 
 199         // From: 1234...78900000...0000.0...0
 200         // To:   1,234...7,890,000,0...0,000
 201         formatted.setLength(0);
 202         from = nonsep_int + nonsep_zero + "." + nonsep_zero;
 203         to   = sep_int + "," + sep_zero;
 204         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 205         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 206 
 207         /* ------------------------------------------------------------------ */
 208 
 209         // From: -1234...78900000...0000.0...0
 210         // To:   -1,234...7,890,000,0...0,000
 211         formatted.setLength(0);
 212         from = "-" + nonsep_int + nonsep_zero + "." + nonsep_zero;
 213         to   = "-" + sep_int + "," + sep_zero;
 214         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 215         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 216 
 217         /* ------------------------------------------------------------------ */
 218 
 219         // From: 000...0000
 220         // To:   0
 221         formatted.setLength(0);
 222         from = nonsep_zero;
 223         to   = "0";
 224         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 225         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 226 
 227         /* ------------------------------------------------------------------ */
 228 
 229         // From: -000...0000
 230         // To:   0
 231         formatted.setLength(0);
 232         from = "-" + nonsep_zero;
 233         to   = "0";
 234         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 235         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 236 
 237         /* ------------------------------------------------------------------ */
 238 
 239         // From: 000...00001234
 240         // To:   1,234
 241         formatted.setLength(0);
 242         from = nonsep_zero + "1234";
 243         to   = "1,234";
 244         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 245         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 246 
 247         /* ------------------------------------------------------------------ */
 248 
 249         // From: -000...00001234
 250         // To:   -1,234
 251         //       ~ : FieldPosition(GROUPING_SEPARATOR)
 252         fp = new FieldPosition(NumberFormat.Field.GROUPING_SEPARATOR);
 253         formatted.setLength(0);
 254         from = "-" + nonsep_zero + "1234";
 255         to   = "-1,234";
 256         nf.format(new BigDecimal(from), formatted, fp);
 257         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 258         checkFieldPosition(from, fp, 2, 3);
 259 
 260         /* ------------------------------------------------------------------ */
 261 
 262         // From: 000...0000.0...0
 263         // To:   0
 264         formatted.setLength(0);
 265         from = nonsep_zero + "." + nonsep_zero;
 266         to   = "0";
 267         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 268         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 269 
 270         /* ------------------------------------------------------------------ */
 271 
 272         ((DecimalFormat)nf).applyPattern("#,##0.0");
 273         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 1);
 274 
 275         // From: -000...0000.0...0
 276         // To:   0.0
 277         formatted.setLength(0);
 278         from = "-" + nonsep_zero + "." + nonsep_zero;
 279         to   = "0.0";
 280         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 281         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 282 
 283         /* ------------------------------------------------------------------ */
 284 
 285         // From: 1234...7890.012...7890...0
 286         // To:   1,234...7,890.0123...789
 287         formatted.setLength(0);
 288         from = nonsep_int + "." + fra + nonsep_zero;
 289         to   = sep_int    + "." + fra;
 290         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 291         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 292 
 293         /* ------------------------------------------------------------------ */
 294 
 295         // From: -1234...7890.012...7890...0
 296         // To:   -1,234...7,890.0123...789
 297         formatted.setLength(0);
 298         from = "-" + nonsep_int + "." + fra + nonsep_zero;
 299         to   = "-" + sep_int    + "." + fra;
 300         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 301         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 302 
 303         /* ------------------------------------------------------------------ */
 304 
 305         ((DecimalFormat)nf).applyPattern("0.###E0");
 306         setDigits(nf, 1, 1, Integer.MAX_VALUE, 0);
 307 
 308         // From: 1123...890.012...789
 309         // To  : 1.123...8900123...789E360
 310         //                           ~~~ : FieldPosition(EXPONENT)
 311         fp = new FieldPosition(NumberFormat.Field.EXPONENT);
 312         formatted.setLength(0);
 313         from = "1"  + nonsep_int + "." + fra;
 314         to   = "1." + nonsep_int       + fra + "E360";
 315         nf.format(new BigDecimal(from), formatted, fp);
 316         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 317         checkFieldPosition(from, fp, 723, 726);
 318 
 319         /* ------------------------------------------------------------------ */
 320 
 321         // From: -1123...890.012...789
 322         // To  : -1.123...8900123...789E360
 323         formatted.setLength(0);
 324         from = "-1"  + nonsep_int + "." + fra;
 325         to   = "-1." + nonsep_int       + fra + "E360";
 326         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 327         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 328 
 329         /* ------------------------------------------------------------------ */
 330 
 331         ((DecimalFormat)nf).applyPattern("0.###E0");
 332         setDigits(nf, 1, 1, Integer.MAX_VALUE, 0);
 333 
 334         // From: 0.000...0001123...890.012...789
 335         // To  : 1.123...8900123...789E-360
 336         formatted.setLength(0);
 337         from = "0." + nonsep_zero + "1" + fra;
 338         to   = "1."                  + fra + "E-361";
 339         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 340         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 341 
 342         /* ------------------------------------------------------------------ */
 343 
 344         // From: -0.000...0001123...890.012...789
 345         // To  : -1.123...8900123...789E-360
 346         formatted.setLength(0);
 347         from = "-0." + nonsep_zero + "1"  + fra;
 348         to   = "-1."                  + fra + "E-361";
 349         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 350         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 351 
 352         /* ------------------------------------------------------------------ */
 353 
 354         // From: 1123...890.012...789000...000
 355         // To  : 1.123...8900123...789E360
 356         formatted.setLength(0);
 357         from = "1"  + nonsep_int + "." + fra + nonsep_zero;
 358         to   = "1." + nonsep_int       + fra + "E360";
 359         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 360         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 361 
 362         /* ------------------------------------------------------------------ */
 363 
 364         // From: -1123...890.012...789000...000
 365         // To  : -1.123...8900123...789E360
 366         //                           ~ : FieldPosition(EXPONENT_SYMBOL)
 367         fp = new FieldPosition(NumberFormat.Field.EXPONENT_SYMBOL);
 368         formatted.setLength(0);
 369         from = "-1"  + nonsep_int + "." + fra + nonsep_zero;
 370         to   = "-1." + nonsep_int       + fra + "E360";
 371         nf.format(new BigDecimal(from), formatted, fp);
 372         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 373         checkFieldPosition(from, fp, 723, 724);
 374 
 375         /* ------------------------------------------------------------------ */
 376 
 377         // From: 0.000...0001123...890.012...789000...000
 378         // To  : 1.123...8900123...789E-360
 379         //                           ~ : FieldPosition(EXPONENT_SIGN)
 380         fp = new FieldPosition(NumberFormat.Field.EXPONENT_SIGN);
 381         formatted.setLength(0);
 382         from = "0." + nonsep_zero + "1" + fra + nonsep_zero;
 383         to   = "1."                  + fra + "E-361";
 384         nf.format(new BigDecimal(from), formatted, fp);
 385         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 386         checkFieldPosition(from, fp, 363, 364);
 387 
 388         /* ------------------------------------------------------------------ */
 389 
 390         // From: -0.000...0001123...890.012...789000...000
 391         // To  : -1.123...8900123...789E-360
 392         formatted.setLength(0);
 393         from = "-0." + nonsep_zero + "1"  + fra + nonsep_zero;
 394         to   = "-1."                  + fra + "E-361";
 395         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 396         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 397 
 398         /* ------------------------------------------------------------------ */
 399 
 400         // From: ABC1123...890.012...789
 401         // To  : ABC1.123...890.0123...789
 402         formatted = new StringBuffer("ABC");
 403         from = "1"     + nonsep_int + "."  + fra;
 404         to   = "ABC1." + nonsep_int     + fra + "E360";
 405         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 406         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 407 
 408         /* ------------------------------------------------------------------ */
 409 
 410         // From: ABC-1123...890.012...789
 411         // To  : ABC-1.123...890.0123...789
 412         //          ~ : FieldPosition(DECIMAL_SEPARATOR)
 413         fp = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
 414         formatted = new StringBuffer("ABC");
 415         from = "-1"     + nonsep_int + "."  + fra;
 416         to   = "ABC-1." + nonsep_int    + fra + "E360";
 417         nf.format(new BigDecimal(from), formatted, fp);
 418         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 419         checkFieldPosition(from, fp, 5, 6);
 420 
 421         /* ------------------------------------------------------------------ */
 422 
 423         ((DecimalFormat)nf).applyPattern("#,##0.###");
 424         setDigits(nf, Integer.MAX_VALUE, 1, 726, 0);
 425 
 426         // From: 0.000...000012...7890123456789
 427         // To:   0.000...000012...789012346 (Shorter than From)
 428         formatted.setLength(0);
 429         from = "0." + nonsep_zero + fra + fra;
 430         to   = "0." + nonsep_zero + fra + "012346";
 431         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 432         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 433 
 434         ((DecimalFormat)nf).applyPattern("#,##0.###");
 435         setDigits(nf, Integer.MAX_VALUE, 1, 723, 0);
 436 
 437         /* ------------------------------------------------------------------ */
 438 
 439         // From: -0.000...000012...7890123456789
 440         // To:   -0.000...000012...789012 (Shorter than From)
 441         formatted.setLength(0);
 442         from = "-0." + nonsep_zero + fra + fra;
 443         to   = "-0." + nonsep_zero + fra + "012";
 444         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 445         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 446 
 447         /* ------------------------------------------------------------------ */
 448 
 449         ((DecimalFormat)nf).applyPattern("00000.###E0");
 450         setDigits(nf, 5, 5, 370, 0);
 451 
 452         // From: 1234567890.012...78901234567890
 453         // To:   12345.67890012...789012346E5
 454         formatted.setLength(0);
 455         from = "1234567890." + fra + "0123456789";
 456         to   = "12345.67890" + fra + "01235E5";
 457         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 458         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 459 
 460         /* ------------------------------------------------------------------ */
 461 
 462         ((DecimalFormat)nf).applyPattern("0.###E0");
 463         setDigits(nf, 1, 1, 364, 0);
 464 
 465         // From: -0.000...0001012...7890123456789
 466         // To:   -1.012...789012E-361
 467         formatted.setLength(0);
 468         from = "-0." + nonsep_zero + "1" + fra + "0123456789";
 469         to   = "-1."                 + fra + "0123E-361";
 470         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 471         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 472 
 473         /* ------------------------------------------------------------------ */
 474 
 475         ((DecimalFormat)nf).applyPattern("0.###E0");
 476         setDigits(nf, 1, 1, 366, 0);
 477 
 478         // From: 1012...78901234567890
 479         // To:   1.012...789012346E370
 480         formatted.setLength(0);
 481         from = "1"  + fra + "0123456789";
 482         to   = "1." + fra + "012346E370";
 483         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 484         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 485 
 486         /* ------------------------------------------------------------------ */
 487 
 488         ((DecimalFormat)nf).applyPattern("0.###E0");
 489         setDigits(nf, 1, 1, 363, 0);
 490 
 491         // From: -1012...7890123456789
 492         // To:   -1.012...789012E370
 493         formatted.setLength(0);
 494         from = "-1"  + fra + "0123456789";
 495         to   = "-1." + fra + "012E370";
 496         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 497         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 498 
 499         /* ------------------------------------------------------------------ */
 500 
 501         ((DecimalFormat)nf).applyPattern("#,##0.###");
 502         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 720);
 503 
 504         // From: 1234...78900000...0000.0...0
 505         // To:   1,234...7,890,000,0...0,000.0...0
 506         formatted.setLength(0);
 507         from = nonsep_int + nonsep_zero + "." + nonsep_zero + nonsep_zero;
 508         to   = sep_int + "," + sep_zero + "." + nonsep_zero + nonsep_zero;
 509         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 510         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 511 
 512         /* ------------------------------------------------------------------ */
 513 
 514         // From: -1234...78900000...0000.0...0
 515         // To:   -1,234...7,890,000,0...0,000.0...0
 516         formatted.setLength(0);
 517         from = "-" + nonsep_int + nonsep_zero + "." + nonsep_zero + nonsep_zero;
 518         to   = "-" + sep_int + "," + sep_zero + "." + nonsep_zero + nonsep_zero;
 519         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 520         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 521     }
 522 
 523     /**
 524      * Test for normal big numbers which have the fraction part with multiplier
 525      */
 526     @Test
 527     void test_Format_in_NumberFormat_BigDecimal_usingMultiplier() {
 528         String from, to;
 529 
 530         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 531         ((DecimalFormat)nf).applyPattern("#,##0.###");
 532         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 533         ((DecimalFormat)nf).setMultiplier(250000000);
 534         ((DecimalFormat)nf).setDecimalSeparatorAlwaysShown(true);
 535 
 536         // From: 1000...0000.000...000
 537         // To:   250,0...0,000.
 538         formatted.setLength(0);
 539         from = "1"          + nonsep_zero + "." + nonsep_zero;
 540         to   = "250,000,000," + sep_zero    + ".";
 541         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 542         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 543 
 544         /* ------------------------------------------------------------------ */
 545 
 546         ((DecimalFormat)nf).setDecimalSeparatorAlwaysShown(false);
 547 
 548         // From: -1000...0000.000...000
 549         // To:   -250,0...0,000
 550         formatted.setLength(0);
 551         from = "-1"         + nonsep_zero + "." + nonsep_zero;
 552         to   = "-250,000,000," + sep_zero;
 553         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 554         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 555 
 556         /* ------------------------------------------------------------------ */
 557 
 558         ((DecimalFormat)nf).applyPattern("#,##0.###");
 559         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 560         ((DecimalFormat)nf).setMultiplier(-250000000);
 561         ((DecimalFormat)nf).setDecimalSeparatorAlwaysShown(true);
 562 
 563         // From: 1000...0000.000...000
 564         // To:   -250,0...0,000.
 565         formatted.setLength(0);
 566         from = "1"          + nonsep_zero + "." + nonsep_zero;
 567         to   = "-250,000,000," + sep_zero    + ".";
 568         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 569         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 570 
 571         /* ------------------------------------------------------------------ */
 572 
 573         ((DecimalFormat)nf).setDecimalSeparatorAlwaysShown(false);
 574 
 575         // From: -1000...0000.000...000
 576         // To:   250,0...0,000
 577         formatted.setLength(0);
 578         from = "-1"         + nonsep_zero + "." + nonsep_zero;
 579         to   = "250,000,000," + sep_zero;
 580         nf.format(new BigDecimal(from), formatted, new FieldPosition(0));
 581         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 582     }
 583 
 584     /**
 585      * Test for normal big numbers which don't have the fraction part
 586      */
 587     @Test
 588     void test_Format_in_NumberFormat_BigInteger() {
 589         String from, to;
 590 
 591         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 592         if (!(nf instanceof DecimalFormat)) {
 593             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 594         }
 595 
 596         ((DecimalFormat)nf).applyPattern("#,##0.###");
 597         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 598 
 599         // From: 1234...7890
 600         // To:   123,4...7,890
 601         formatted.setLength(0);
 602         from = nonsep_int;
 603         to   = sep_int;
 604         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 605         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 606 
 607         /* ------------------------------------------------------------------ */
 608 
 609         // From: -1234...7890
 610         // To:   -123,4...7,890
 611         //      ~~~~~~~~~~~~~ : FieldPosition(INTEGER_FIELD)
 612         fp = new FieldPosition(DecimalFormat.INTEGER_FIELD);
 613         formatted.setLength(0);
 614         from = "-" + nonsep_int;
 615         to   = "-" + sep_int;
 616         nf.format(new BigInteger(from), formatted, fp);
 617         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 618         checkFieldPosition(from, fp, 1, 480);
 619 
 620         /* ------------------------------------------------------------------ */
 621 
 622         // From: 000...0001234...7890
 623         // To:   123,4...7,890
 624         formatted.setLength(0);
 625         from = nonsep_zero + nonsep_int;
 626         to   = sep_int;
 627         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 628         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 629 
 630         /* ------------------------------------------------------------------ */
 631 
 632         // From: -000...0001234...7890
 633         // To:   -123,4...7,890
 634         //       ~ : FieldPosition(SIGN)
 635         fp = new FieldPosition(NumberFormat.Field.SIGN);
 636         formatted.setLength(0);
 637         from = "-" + nonsep_zero + nonsep_int;
 638         to   = "-" + sep_int;
 639         nf.format(new BigInteger(from), formatted, fp);
 640         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 641         checkFieldPosition(from, fp, 0, 1);
 642 
 643         /* ------------------------------------------------------------------ */
 644 
 645         // From: 000...0000
 646         // To:   0
 647         formatted.setLength(0);
 648         from = nonsep_zero;
 649         to   = "0";
 650         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 651         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 652 
 653         /* ------------------------------------------------------------------ */
 654 
 655         ((DecimalFormat)nf).applyPattern("#,##0.0");
 656         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 1);
 657 
 658         // From: -000...0000
 659         // To:   0.0
 660         fp = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
 661         formatted.setLength(0);
 662         from = "-" + nonsep_zero;
 663         to   = "0.0";
 664         nf.format(new BigInteger(from), formatted, fp);
 665         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 666         checkFieldPosition(from, fp, 1, 2);
 667 
 668         /* ------------------------------------------------------------------ */
 669 
 670         ((DecimalFormat)nf).applyPattern("0.###E0");
 671         setDigits(nf, 1, 1, Integer.MAX_VALUE, 0);
 672 
 673         // From: 10123...789
 674         // To  : 1.0123...789E360
 675         //                  ~~~ : FieldPosition(EXPONENT)
 676         fp = new FieldPosition(NumberFormat.Field.EXPONENT);
 677         formatted.setLength(0);
 678         from = "1"  + fra;
 679         to   = "1." + fra + "E360";
 680         nf.format(new BigInteger(from), formatted, fp);
 681         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 682         checkFieldPosition(from, fp, 363, 366);
 683 
 684         /* ------------------------------------------------------------------ */
 685 
 686         // From: -1012...789
 687         // To  : -1.012...789E360
 688         formatted.setLength(0);
 689         from = "-1"  + fra;
 690         to   = "-1." + fra + "E360";
 691         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 692         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 693 
 694         /* ------------------------------------------------------------------ */
 695 
 696         ((DecimalFormat)nf).applyPattern("00000.###E0");
 697         setDigits(nf, 5, 5, Integer.MAX_VALUE, 720);
 698 
 699         // From: 12345012...789000...000
 700         // To  : 12345.012...789000...000E720
 701         //                              ~~~ : FieldPosition(EXPONENT)
 702         fp = new FieldPosition(NumberFormat.Field.EXPONENT);
 703         formatted.setLength(0);
 704         from = "12345"  + fra + nonsep_zero;
 705         to   = "12345." + fra + nonsep_zero + "E720";
 706         nf.format(new BigInteger(from), formatted, fp);
 707         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 708         checkFieldPosition(from, fp, 727, 730);
 709 
 710         /* ------------------------------------------------------------------ */
 711 
 712         ((DecimalFormat)nf).applyPattern("00000.###E0");
 713         setDigits(nf, 5, 5, Integer.MAX_VALUE, 365);
 714 
 715         // From: -1234567890012...789000...000
 716         // To  : -12345.67890012...789E365
 717         formatted.setLength(0);
 718         from = "-1234567890"  + fra;
 719         to   = "-12345.67890" + fra + "E365";
 720         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 721         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 722     }
 723 
 724     /**
 725      * Test for normal big numbers which don't have the fraction part with
 726      * multiplier
 727      */
 728     @Test
 729     void test_Format_in_NumberFormat_BigInteger_usingMultiplier() {
 730         String from, to;
 731 
 732         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 733 
 734         ((DecimalFormat)nf).applyPattern("#,##0.###");
 735         ((DecimalFormat)nf).setMultiplier(250000000);
 736         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 737 
 738         // From: 1000...0000
 739         // To:   250,0...0,000
 740         formatted.setLength(0);
 741         from = "1" + nonsep_zero;
 742         to   = "250,000,000," + sep_zero;
 743         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 744         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 745 
 746         /* ------------------------------------------------------------------ */
 747 
 748         // From: -1000...0000
 749         // To:   -250,0...0,000
 750         formatted.setLength(0);
 751         from = "-1" + nonsep_zero;
 752         to   = "-250,000,000," + sep_zero;
 753         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 754         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 755         /* ------------------------------------------------------------------ */
 756 
 757         ((DecimalFormat)nf).applyPattern("#,##0.###");
 758         ((DecimalFormat)nf).setMultiplier(-250000000);
 759         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 760 
 761         // From: 1000...0000
 762         // To:   -250,0...0,000
 763         formatted.setLength(0);
 764         from = "1" + nonsep_zero;
 765         to   = "-250,000,000," + sep_zero;
 766         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 767         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 768 
 769         /* ------------------------------------------------------------------ */
 770 
 771         // From: -1000...0000
 772         // To:   250,0...0,000
 773         formatted.setLength(0);
 774         from = "-1" + nonsep_zero;
 775         to   = "250,000,000," + sep_zero;
 776         nf.format(new BigInteger(from), formatted, new FieldPosition(0));
 777         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 778     }
 779 
 780     /**
 781      * Test for normal Long numbers when maximum and minimum digits are
 782      * specified
 783      */
 784     @Test
 785     void test_Format_in_NumberFormat_Long_checkDigits() {
 786         String from, to;
 787 
 788         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 789         if (!(nf instanceof DecimalFormat)) {
 790             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 791         }
 792 
 793         ((DecimalFormat)nf).applyPattern("#,##0.###");
 794         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 795 
 796         // From: 1234567890
 797         // To:   000,0...0,000,123,456,789
 798         //       -------------
 799         //       300 zeros
 800         formatted.setLength(0);
 801         from = "123456789";
 802         to   = sep_zero.substring(0, 399) + ",123,456,789";
 803         nf.format(123456789L, formatted, new FieldPosition(0));
 804         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 805 
 806         /* ------------------------------------------------------------------ */
 807 
 808         ((DecimalFormat)nf).applyPattern("##0.###");
 809         ((DecimalFormat)nf).setMultiplier(-1);
 810         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 811 
 812         // From: 1234567890
 813         // To:   -0000...0000123456789.000...000
 814         //      -------------
 815         //        300 zeros
 816         formatted.setLength(0);
 817         from = "123456789";
 818         to   = "-" + nonsep_zero.substring(0, 300) + "123456789." +
 819                nonsep_zero.substring(0, 340);
 820         nf.format(123456789L, formatted, new FieldPosition(0));
 821         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 822 
 823         /* ------------------------------------------------------------------ */
 824 
 825         ((DecimalFormat)nf).applyPattern("#,##0.###");
 826         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 827         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 0);
 828 
 829         // From: Long.MAX_VALUE
 830         // To:   000,0...0,000,019,807,040,619,342,712,359,383,728,129
 831         //       ---------------
 832         //       280 zeros
 833         formatted.setLength(0);
 834         from = Long.toString(Long.MAX_VALUE);
 835         to   = sep_zero.substring(0, 373) +
 836                "19,807,040,619,342,712,359,383,728,129";
 837         nf.format(Long.MAX_VALUE, formatted, new FieldPosition(0));
 838         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 839 
 840         /* ------------------------------------------------------------------ */
 841 
 842         ((DecimalFormat)nf).applyPattern("0.###E0");
 843         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 844         setDigits(nf, 1, 1, Integer.MAX_VALUE, 360);
 845 
 846         // From: Long.MAX_VALUE
 847         // To:   -1.9807040628566084396238503936000...000E28
 848         //                                      ---------
 849         //                                      312 zeros
 850         formatted.setLength(0);
 851         from = Long.toString(Long.MAX_VALUE);
 852         to   = "-1.9807040628566084396238503936" +
 853                nonsep_zero.substring(0, 312) + "E28";
 854         nf.format(Long.MAX_VALUE, formatted, new FieldPosition(0));
 855         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 856 
 857         /* ------------------------------------------------------------------ */
 858 
 859         ((DecimalFormat)nf).applyPattern("##0.###E0");
 860         ((DecimalFormat)nf).setMultiplier(Integer.MAX_VALUE);
 861         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 862 
 863         // From: Long.MIN_VALUE
 864         // To:   -198070406193427123615312117760000...0000.000...000E-280
 865         //                                     ----------- ---------
 866         //                                      280 zeros  340 zeros
 867         formatted.setLength(0);
 868         from = Long.toString(Long.MIN_VALUE);
 869         to   = "-19807040619342712361531211776" +
 870                nonsep_zero.substring(0, 280) + "." +
 871                nonsep_zero.substring(0, 340) + "E-280";
 872         nf.format(Long.MIN_VALUE, formatted, new FieldPosition(0));
 873         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 874 
 875         /* ------------------------------------------------------------------ */
 876 
 877         ((DecimalFormat)nf).applyPattern("#,##0.###");
 878         ((DecimalFormat)nf).setMultiplier(Integer.MIN_VALUE);
 879         setDigits(nf, Integer.MAX_VALUE, 360, Integer.MAX_VALUE, 360);
 880 
 881         // From: Long.MIN_VALUE
 882         // To:   000,0...0,000,019,807,040,628,566,084,398,385,987,584.000...000
 883         //       ---------------                                       ---------
 884         //          280 zeros                                          340 zeros
 885         formatted.setLength(0);
 886         from = Long.toString(Long.MIN_VALUE);
 887         to   = sep_zero.substring(0, 373) +
 888                "19,807,040,628,566,084,398,385,987,584." +
 889                nonsep_zero.substring(0, 340);
 890         nf.format(Long.MIN_VALUE, formatted, new FieldPosition(0));
 891         checkFormat(from, formatted, to, ((DecimalFormat)nf).getMultiplier());
 892     }
 893 
 894     /**
 895      * Test for special numbers
 896      *    Double.NaN
 897      *    Double.POSITIVE_INFINITY
 898      *    Double.NEGATIVE_INFINITY
 899      */
 900     @Test
 901     void test_Format_in_NumberFormat_SpecialNumber() {
 902         String from, to;
 903 
 904         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 905         if (!(nf instanceof DecimalFormat)) {
 906             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 907         }
 908 
 909         ((DecimalFormat)nf).applyPattern("#,##0.###");
 910         setDigits(nf, Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
 911 
 912         double[] numbers = {
 913             -0.0, 0.0, Double.NaN,
 914             Double.POSITIVE_INFINITY, 5.1, 5.0,
 915             Double.NEGATIVE_INFINITY, -5.1, -5.0,
 916         };
 917         int multipliers[] = {0, 5, -5};
 918         String[][] expected = {
 919             {"-0", "0", "\ufffd", "\ufffd", "0", "0", "\ufffd", "-0", "-0"},
 920             {"-0", "0", "\ufffd", "\u221e", "25.5", "25", "-\u221e", "-25.5",
 921              "-25"},
 922             {"0", "-0", "\ufffd", "-\u221e", "-25.5", "-25", "\u221e", "25.5",
 923              "25"},
 924         };
 925 
 926         for (int i = 0; i < multipliers.length; i++) {
 927             ((DecimalFormat)nf).setMultiplier(multipliers[i]);
 928             for (int j = 0; j < numbers.length; j++) {
 929                 formatted.setLength(0);
 930                 from = String.valueOf(numbers[j]);
 931                 nf.format(numbers[j], formatted, new FieldPosition(0));
 932                 checkFormat(from, formatted, expected[i][j],
 933                             ((DecimalFormat)nf).getMultiplier());
 934             }
 935         }
 936     }
 937 
 938     /**
 939      * Test for Long.MIN_VALUE
 940      *   (Formatting Long.MIN_VALUE w/ multiplier=-1 used to return a wrong
 941      *    number.)
 942      */
 943     @Test
 944     void test_Format_in_NumberFormat_Other() {
 945         String from, to;
 946 
 947         NumberFormat nf = NumberFormat.getInstance(Locale.US);
 948         if (!(nf instanceof DecimalFormat)) {
 949             throw new RuntimeException("Couldn't get DecimalFormat instance.");
 950         }
 951 
 952         long[] numbers = {
 953             Long.MIN_VALUE,
 954         };
 955         int multipliers[] = {1, -1};
 956         String[][] expected = {
 957             {"-9,223,372,036,854,775,808"},     // Long.MIN_VALUE
 958             {"9,223,372,036,854,775,808"},      // Long.MIN_VALUE * (-1)
 959         };
 960 
 961         for (int i = 0; i < multipliers.length; i++) {
 962             ((DecimalFormat)nf).setMultiplier(multipliers[i]);
 963             for (int j = 0; j < numbers.length; j++) {
 964                 formatted.setLength(0);
 965                 from = String.valueOf(numbers[j]);
 966                 nf.format(numbers[j], formatted, new FieldPosition(0));
 967                 checkFormat(from, formatted, expected[i][j],
 968                             ((DecimalFormat)nf).getMultiplier());
 969             }
 970         }
 971     }
 972 
 973     /**
 974      * Test for MessageFormat
 975      */
 976     @Test
 977     void test_Format_in_MessageFormat() {
 978         MessageFormat mf = new MessageFormat(
 979             "  {0, number}\n" +
 980             "  {0, number, integer}\n" +
 981             "  {0, number, currency}\n" +
 982             "  {0, number, percent}\n" +
 983             "  {0, number,0.###########E0}\n" +
 984 
 985             "  {1, number}\n" +
 986             "  {1, number, integer}\n" +
 987             "  {1, number, currency}\n" +
 988             "  {1, number, percent}\n" +
 989             "  {1, number,0.#######E0}\n",
 990             Locale.US
 991         );
 992         Object[] testArgs = {
 993             new BigInteger("9876543210987654321098765432109876543210"),
 994             new BigDecimal("-12345678901234567890.98765432109876543210987654321"),
 995         };
 996         String expected =
 997             "  9,876,543,210,987,654,321,098,765,432,109,876,543,210\n" +
 998             "  9,876,543,210,987,654,321,098,765,432,109,876,543,210\n" +
 999             "  $9,876,543,210,987,654,321,098,765,432,109,876,543,210.00\n" +
1000             "  987,654,321,098,765,432,109,876,543,210,987,654,321,000%\n" +
1001             "  9.87654321099E39\n" +
1002 
1003             "  -12,345,678,901,234,567,890.988\n" +
1004             "  -12,345,678,901,234,567,891\n" +
1005             "  ($12,345,678,901,234,567,890.99)\n" +
1006             "  -1,234,567,890,123,456,789,099%\n" +
1007             "  -1.2345679E19\n"
1008         ;
1009 
1010         if (!expected.equals(mf.format(testArgs))) {
1011             fail("Wrong format.\n      got:\n" + mf.format(testArgs) +
1012                   "     expected:\n" + expected);
1013         }
1014     }
1015 
1016     private void setDigits(NumberFormat nf,
1017                            int i_max, int i_min, int f_max, int f_min) {
1018         nf.setMaximumIntegerDigits(i_max);
1019         nf.setMinimumIntegerDigits(i_min);
1020         nf.setMaximumFractionDigits(f_max);
1021         nf.setMinimumFractionDigits(f_min);
1022     }
1023 
1024     private void checkFormat(String orig, StringBuffer got, String expected,
1025                              int multiplier) {
1026         if (!expected.equals(new String(got))) {
1027             fail("Formatting... failed." +
1028                   "\n   original:   " + orig +
1029                   "\n   multiplier: " + multiplier +
1030                   "\n   formatted:  " + got +
1031                   "\n   expected:   " + expected + "\n");
1032         }
1033     }
1034 
1035     private void checkFieldPosition(String orig, FieldPosition fp, int begin,
1036                                     int end) {
1037         int position;
1038 
1039         if ((position = fp.getBeginIndex()) != begin) {
1040             fail("Formatting... wrong Begin index returned for " +
1041                   fp.getFieldAttribute() + "." +
1042                   "\n   original: " + orig +
1043                   "\n   got:      " + position +
1044                   "\n   expected: " + begin + "\n");
1045         }
1046         if ((position = fp.getEndIndex()) != end) {
1047             fail("Formatting... wrong End index returned for " +
1048                   fp.getFieldAttribute() + "." +
1049                   "\n   original: " + orig +
1050                   "\n   got:      " + position +
1051                   "\n   expected: " + end + "\n");
1052         }
1053     }
1054 }