< prev index next >

test/jdk/java/text/Format/NumberFormat/BigDecimalFormat.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 23,24 ***
  
  /*
   * @test
   * @bug 4018937 8008577
   * @summary Confirm that methods which are newly added to support BigDecimal and BigInteger work as expected.
!  * @library /java/text/testlib
-  * @run main/othervm -Djava.locale.providers=COMPAT,SPI BigDecimalFormat
   */
  
  import java.math.BigDecimal;
  import java.math.BigInteger;
! import java.text.*;
! import java.util.*;
  
! public class BigDecimalFormat extends IntlTest {
  
!     public static void main(String[] args) throws Exception {
!         new BigDecimalFormat().run(args);
!     }
  
      static final String nonsep_int =
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +
--- 23,26 ---
  
  /*
   * @test
   * @bug 4018937 8008577
   * @summary Confirm that methods which are newly added to support BigDecimal and BigInteger work as expected.
!  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI BigDecimalFormat
   */
  
  import java.math.BigDecimal;
  import java.math.BigInteger;
! import java.text.DecimalFormat;
! import java.text.FieldPosition;
+ import java.text.MessageFormat;
+ import java.text.NumberFormat;
+ import java.util.Locale;
  
! import org.junit.jupiter.api.Test;
  
! import static org.junit.jupiter.api.Assertions.fail;
! 
! public class BigDecimalFormat {
  
      static final String nonsep_int =
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +

*** 97,10 ***
--- 99,11 ---
      FieldPosition fp;
  
      /**
       * Test for normal big numbers which have the fraction part
       */
+     @Test
      void test_Format_in_NumberFormat_BigDecimal() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          ((DecimalFormat)nf).applyPattern("#,##0.###");

*** 518,10 ***
--- 521,11 ---
      }
  
      /**
       * Test for normal big numbers which have the fraction part with multiplier
       */
+     @Test
      void test_Format_in_NumberFormat_BigDecimal_usingMultiplier() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          ((DecimalFormat)nf).applyPattern("#,##0.###");

*** 578,10 ***
--- 582,11 ---
      }
  
      /**
       * Test for normal big numbers which don't have the fraction part
       */
+     @Test
      void test_Format_in_NumberFormat_BigInteger() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          if (!(nf instanceof DecimalFormat)) {

*** 718,10 ***
--- 723,11 ---
  
      /**
       * Test for normal big numbers which don't have the fraction part with
       * multiplier
       */
+     @Test
      void test_Format_in_NumberFormat_BigInteger_usingMultiplier() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
  

*** 773,10 ***
--- 779,11 ---
  
      /**
       * Test for normal Long numbers when maximum and minimum digits are
       * specified
       */
+     @Test
      void test_Format_in_NumberFormat_Long_checkDigits() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          if (!(nf instanceof DecimalFormat)) {

*** 888,10 ***
--- 895,11 ---
       * Test for special numbers
       *    Double.NaN
       *    Double.POSITIVE_INFINITY
       *    Double.NEGATIVE_INFINITY
       */
+     @Test
      void test_Format_in_NumberFormat_SpecialNumber() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          if (!(nf instanceof DecimalFormat)) {

*** 930,10 ***
--- 938,11 ---
      /**
       * Test for Long.MIN_VALUE
       *   (Formatting Long.MIN_VALUE w/ multiplier=-1 used to return a wrong
       *    number.)
       */
+     @Test
      void test_Format_in_NumberFormat_Other() {
          String from, to;
  
          NumberFormat nf = NumberFormat.getInstance(Locale.US);
          if (!(nf instanceof DecimalFormat)) {

*** 962,10 ***
--- 971,11 ---
      }
  
      /**
       * Test for MessageFormat
       */
+     @Test
      void test_Format_in_MessageFormat() {
          MessageFormat mf = new MessageFormat(
              "  {0, number}\n" +
              "  {0, number, integer}\n" +
              "  {0, number, currency}\n" +

*** 996,11 ***
              "  -1,234,567,890,123,456,789,099%\n" +
              "  -1.2345679E19\n"
          ;
  
          if (!expected.equals(mf.format(testArgs))) {
!             errln("Wrong format.\n      got:\n" + mf.format(testArgs) +
                    "     expected:\n" + expected);
          }
      }
  
      private void setDigits(NumberFormat nf,
--- 1006,11 ---
              "  -1,234,567,890,123,456,789,099%\n" +
              "  -1.2345679E19\n"
          ;
  
          if (!expected.equals(mf.format(testArgs))) {
!             fail("Wrong format.\n      got:\n" + mf.format(testArgs) +
                    "     expected:\n" + expected);
          }
      }
  
      private void setDigits(NumberFormat nf,

*** 1012,11 ***
      }
  
      private void checkFormat(String orig, StringBuffer got, String expected,
                               int multiplier) {
          if (!expected.equals(new String(got))) {
!             errln("Formatting... failed." +
                    "\n   original:   " + orig +
                    "\n   multiplier: " + multiplier +
                    "\n   formatted:  " + got +
                    "\n   expected:   " + expected + "\n");
          }
--- 1022,11 ---
      }
  
      private void checkFormat(String orig, StringBuffer got, String expected,
                               int multiplier) {
          if (!expected.equals(new String(got))) {
!             fail("Formatting... failed." +
                    "\n   original:   " + orig +
                    "\n   multiplier: " + multiplier +
                    "\n   formatted:  " + got +
                    "\n   expected:   " + expected + "\n");
          }

*** 1025,18 ***
      private void checkFieldPosition(String orig, FieldPosition fp, int begin,
                                      int end) {
          int position;
  
          if ((position = fp.getBeginIndex()) != begin) {
!             errln("Formatting... wrong Begin index returned for " +
                    fp.getFieldAttribute() + "." +
                    "\n   original: " + orig +
                    "\n   got:      " + position +
                    "\n   expected: " + begin + "\n");
          }
          if ((position = fp.getEndIndex()) != end) {
!             errln("Formatting... wrong End index returned for " +
                    fp.getFieldAttribute() + "." +
                    "\n   original: " + orig +
                    "\n   got:      " + position +
                    "\n   expected: " + end + "\n");
          }
--- 1035,18 ---
      private void checkFieldPosition(String orig, FieldPosition fp, int begin,
                                      int end) {
          int position;
  
          if ((position = fp.getBeginIndex()) != begin) {
!             fail("Formatting... wrong Begin index returned for " +
                    fp.getFieldAttribute() + "." +
                    "\n   original: " + orig +
                    "\n   got:      " + position +
                    "\n   expected: " + begin + "\n");
          }
          if ((position = fp.getEndIndex()) != end) {
!             fail("Formatting... wrong End index returned for " +
                    fp.getFieldAttribute() + "." +
                    "\n   original: " + orig +
                    "\n   got:      " + position +
                    "\n   expected: " + end + "\n");
          }
< prev index next >