< prev index next >

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

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2003, 2023, 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,31 +23,31 @@
  
  /*
   * @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 BigDecimalParse
+  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI BigDecimalParse
   */
  
  import java.math.BigDecimal;
  import java.text.*;
  import java.util.*;
  
- public class BigDecimalParse extends IntlTest {
+ import org.junit.jupiter.api.Test;
+ import org.junit.jupiter.api.BeforeAll;
  
-     public static void main(String[] args) throws Exception {
-         Locale loc = Locale.getDefault();
-         try {
-             Locale.setDefault(Locale.US);
-             new BigDecimalParse().run(args);
-         } finally {
-             // restore the reserved locale
-             Locale.setDefault(loc);
-         }
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class BigDecimalParse {
+ 
+     // Change JVM default Locale
+     @BeforeAll
+     static void initAll() {
+         Locale.setDefault(Locale.US);
      }
  
+ 
      static final String nonsep_int =
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +
          "123456789012345678901234567890123456789012345678901234567890" +

@@ -106,11 +106,12 @@
      DecimalFormat df;
  
      /**
       * Test for normal big numbers which have the fraction part
       */
-     void test_Parse_in_DecimalFormat_BigDecimal() {
+     @Test
+     public void test_Parse_in_DecimalFormat_BigDecimal() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          // From: 1234...7890.012...789
          // To:   BigDecimal 1234...7890.012...789

@@ -148,11 +149,12 @@
      }
  
      /**
       * Test for normal big numbers which have the fraction part with multiplier
       */
-     void test_Parse_in_DecimalFormat_BigDecimal_usingMultiplier() {
+     @Test
+     public void test_Parse_in_DecimalFormat_BigDecimal_usingMultiplier() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          // From: 250,0...0,000.000...000
          // To:   1000...0000.000...000

@@ -190,11 +192,12 @@
      }
  
      /**
       * Test for division by zero (BigDecimal)
       */
-     void test_Parse_in_DecimalFormat_BigDecimal_DivisionByZero() {
+     @Test
+     public void test_Parse_in_DecimalFormat_BigDecimal_DivisionByZero() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
          df.setMultiplier(0);
  
          // From: 1000.000

@@ -211,11 +214,12 @@
      }
  
      /**
       * Test for division by zero (Double)
       */
-     void test_Parse_in_DecimalFormat_Double_DivisionByZero() {
+     @Test
+     public void test_Parse_in_DecimalFormat_Double_DivisionByZero() {
          df = new DecimalFormat();
          df.setParseBigDecimal(false);
          df.setMultiplier(0);
  
          // From: 1000.000

@@ -248,11 +252,12 @@
      }
  
      /**
       * Test for division by zero (Long)
       */
-     void test_Parse_in_DecimalFormat_Long_DivisionByZero() {
+     @Test
+     public void test_Parse_in_DecimalFormat_Long_DivisionByZero() {
          df = new DecimalFormat();
          df.setParseBigDecimal(false);
          df.setMultiplier(0);
  
          // From: 1000

@@ -269,11 +274,12 @@
      }
  
      /**
       * Test for normal big numbers which don't have the fraction part
       */
-     void test_Parse_in_DecimalFormat_BigInteger() {
+     @Test
+     public void test_Parse_in_DecimalFormat_BigInteger() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          // From: 123...890
          // To:   BigDecimal 123...890

@@ -294,11 +300,12 @@
  
      /**
       * Test for normal big numbers which don't have the fraction part with
       * multiplier
       */
-     void test_Parse_in_DecimalFormat_BigInteger_usingMultiplier() {
+     @Test
+     public void test_Parse_in_DecimalFormat_BigInteger_usingMultiplier() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          // From: 250,0...0,000
          // To:   1000...0000

@@ -335,11 +342,12 @@
       * Test for special numbers
       *    Double.NaN
       *    Double.POSITIVE_INFINITY
       *    Double.NEGATIVE_INFINITY
       */
-     void test_Parse_in_DecimalFormat_SpecialNumber() {
+     @Test
+     public void test_Parse_in_DecimalFormat_SpecialNumber() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          String[] numbers = {
              "0", "0.0", "25", "25.0", "25.5", "\u221e", "\ufffd",

@@ -376,11 +384,12 @@
      }
  
      /**
       * Test for special numbers
       */
-     void test_Parse_in_DecimalFormat_Other() {
+     @Test
+     public void test_Parse_in_DecimalFormat_Other() {
          df = new DecimalFormat();
          df.setParseBigDecimal(true);
  
          String[] numbers = {
              "-9223372036854775808",     // Long.MIN_VALUE

@@ -470,11 +479,12 @@
      };
  
      /**
       * Test for MessageFormat: setParseIntegerOnly(false)
       */
-     void test_Parse_in_MessageFormat_NotParseIntegerOnly() {
+     @Test
+     public void test_Parse_in_MessageFormat_NotParseIntegerOnly() {
          for (int i=0; i < patterns.length; i++) {
              pp = new ParsePosition(0);
              Object[] parsed = null;
  
              try {

@@ -485,23 +495,23 @@
                  }
  
                  parsed = mf.parse(from[i], pp);
  
                  if (pp.getErrorIndex() != -1) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getErrorIndex() returns wrong value. expected:-1, got:"+
                            pp.getErrorIndex() + " for " + from[i]);
                  }
                  if (pp.getIndex() != parsePosition1[i]) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getIndex() returns wrong value. expected:" +
                            parsePosition1[i] + ", got:"+ pp.getIndex() +
                            " for " + from[i]);
                  }
              }
              catch(Exception e) {
-                 errln("Unexpected exception: " + e.getMessage());
+                 fail("Unexpected exception: " + e.getMessage());
              }
  
              checkType(from[i], getType(new BigDecimal(expected1[i])),
                        getType((Number)parsed[0]));
              checkParse(from[i], new BigDecimal(expected1[i]),

@@ -556,11 +566,12 @@
      };
  
      /**
       * Test for MessageFormat: setParseIntegerOnly(true)
       */
-     void test_Parse_in_MessageFormat_ParseIntegerOnly() {
+     @Test
+     public void test_Parse_in_MessageFormat_ParseIntegerOnly() {
          for (int i=0; i < patterns.length; i++) {
              pp = new ParsePosition(0);
              Object[] parsed = null;
  
              try {

@@ -572,24 +583,24 @@
                  }
  
                  parsed = mf.parse(from[i], pp);
  
                  if (pp.getErrorIndex() != parsePosition2[i][0]) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getErrorIndex() returns wrong value. expected:" +
                            parsePosition2[i][0] + ", got:"+ pp.getErrorIndex() +
                            " for " + from[i]);
                  }
                  if (pp.getIndex() != parsePosition2[i][1]) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getIndex() returns wrong value. expected:" +
                            parsePosition2[i][1] + ", got:"+ pp.getIndex() +
                            " for " + from[i]);
                  }
              }
              catch(Exception e) {
-                 errln("Unexpected exception: " + e.getMessage());
+                 fail("Unexpected exception: " + e.getMessage());
              }
  
              if (parsePosition2[i][0] == -1) {
                  checkType(from[i], getType(new BigDecimal(expected2[i])),
                            getType((Number)parsed[0]));

@@ -622,11 +633,12 @@
      };
  
      /**
       * Test for DecimalFormat: setParseIntegerOnly(true)
       */
-     void test_Parse_in_DecimalFormat_ParseIntegerOnly() {
+     @Test
+     public void test_Parse_in_DecimalFormat_ParseIntegerOnly() {
          DecimalFormat df = (DecimalFormat)NumberFormat.getIntegerInstance();
          df.setParseBigDecimal(true);
  
          for (int i=0; i < from3.length; i++) {
              pp = new ParsePosition(0);

@@ -634,24 +646,24 @@
  
              try {
                  parsed = df.parse(from3[i], pp);
  
                  if (pp.getErrorIndex() != parsePosition3[i][0]) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getErrorIndex() returns wrong value. expected:" +
                            parsePosition3[i][0] + ", got:"+ pp.getErrorIndex() +
                            " for " + from3[i]);
                  }
                  if (pp.getIndex() != parsePosition3[i][1]) {
-                     errln("Case" + (i+1) +
+                     fail("Case" + (i+1) +
                            ": getIndex() returns wrong value. expected:" +
                            parsePosition3[i][1] + ", got:"+ pp.getIndex() +
                            " for " + from3[i]);
                  }
              }
              catch(Exception e) {
-                 errln("Unexpected exception: " + e.getMessage());
+                 fail("Unexpected exception: " + e.getMessage());
              }
  
              if (parsePosition3[i][0] == -1) {
                  checkType(from3[i], getType(new BigDecimal(expected3[i])),
                            getType(parsed));

@@ -665,40 +677,40 @@
          try {
              parsed = df.parse(from, pp);
          }
          catch(Exception e) {
              exceptionOccurred = true;
-             errln(e.getMessage());
+             fail(e.getMessage());
          }
          if (!exceptionOccurred) {
              checkParse(from, to, parsed);
              checkType(from, getType(to), getType(parsed));
              checkParsePosition(from, from.length(), pp.getIndex());
          }
      }
  
      private void checkParse(String orig, Number expected, Number got) {
          if (!expected.equals(got)) {
-             errln("Parsing... failed." +
+             fail("Parsing... failed." +
                    "\n   original: " + orig +
                    "\n   parsed:   " + got +
                    "\n   expected: " + expected + "\n");
          }
      }
  
      private void checkType(String orig, String expected, String got) {
          if (!expected.equals(got)) {
-             errln("Parsing... unexpected Class returned." +
+             fail("Parsing... unexpected Class returned." +
                    "\n   original: " + orig +
                    "\n   got:      " + got +
                    "\n   expected: " + expected + "\n");
          }
      }
  
      private void checkParsePosition(String orig, int expected, int got) {
          if (expected != got) {
-             errln("Parsing... wrong ParsePosition returned." +
+             fail("Parsing... wrong ParsePosition returned." +
                    "\n   original: " + orig +
                    "\n   got:      " + got +
                    "\n   expected: " + expected + "\n");
          }
      }
< prev index next >