< prev index next >

test/jdk/java/text/Format/DateFormat/IntlTestSimpleDateFormatAPI.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1998, 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,12 +23,11 @@
  
  /*
   * @test
   * @summary test International Simple Date Format API
   * @bug 8008577
-  * @library /java/text/testlib
-  * @run main/othervm -Djava.locale.providers=COMPAT,SPI IntlTestSimpleDateFormatAPI
+  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI IntlTestSimpleDateFormatAPI
   */
  /*
  (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
  

@@ -41,32 +40,29 @@
  */
  
  import java.text.*;
  import java.util.*;
  
- public class IntlTestSimpleDateFormatAPI extends IntlTest
+ import org.junit.jupiter.api.Test;
+ import org.junit.jupiter.api.BeforeAll;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class IntlTestSimpleDateFormatAPI
  {
-     public static void main(String[] args) throws Exception {
-         Locale reservedLocale = Locale.getDefault();
-         try {
-             new IntlTestSimpleDateFormatAPI().run(args);
-         } finally {
-             // restore the reserved locale
-             Locale.setDefault(reservedLocale);
-         }
-     }
  
      // This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
+     @Test
      public void TestAPI()
      {
-         logln("SimpleDateFormat API test---"); logln("");
+         System.out.println("SimpleDateFormat API test---"); System.out.println("");
  
          Locale.setDefault(Locale.ENGLISH);
  
          // ======= Test constructors
  
-         logln("Testing SimpleDateFormat constructors");
+         System.out.println("Testing SimpleDateFormat constructors");
  
          SimpleDateFormat def = new SimpleDateFormat();
  
          final String pattern = new String("yyyy.MM.dd G 'at' hh:mm:ss z");
          SimpleDateFormat pat = new SimpleDateFormat(pattern);

@@ -77,99 +73,99 @@
  
          SimpleDateFormat cust1 = new SimpleDateFormat(pattern, symbols);
  
          // ======= Test clone() and equality
  
-         logln("Testing clone(), assignment and equality operators");
+         System.out.println("Testing clone(), assignment and equality operators");
  
          Format clone = (Format) def.clone();
          if( ! clone.equals(def) ) {
-             errln("ERROR: Format clone or equals failed");
+             fail("ERROR: Format clone or equals failed");
          }
  
          // ======= Test various format() methods
  
-         logln("Testing various format() methods");
+         System.out.println("Testing various format() methods");
  
          Date d = new Date((long)837039928046.0);
  
          StringBuffer res1 = new StringBuffer();
          StringBuffer res2 = new StringBuffer();
          FieldPosition pos1 = new FieldPosition(0);
          FieldPosition pos2 = new FieldPosition(0);
  
          res1 = def.format(d, res1, pos1);
-         logln( "" + d.getTime() + " formatted to " + res1);
+         System.out.println( "" + d.getTime() + " formatted to " + res1);
  
          res2 = cust1.format(d, res2, pos2);
-         logln("" + d.getTime() + " formatted to " + res2);
+         System.out.println("" + d.getTime() + " formatted to " + res2);
  
          // ======= Test parse()
  
-         logln("Testing parse()");
+         System.out.println("Testing parse()");
  
          String text = new String("02/03/76 2:50 AM, CST");
          Date result1 = new Date();
          Date result2 = new Date();
          ParsePosition pos= new ParsePosition(0);
          result1 = def.parse(text, pos);
-         logln(text + " parsed into " + result1);
+         System.out.println(text + " parsed into " + result1);
  
          try {
              result2 = def.parse(text);
          }
          catch (ParseException e) {
-             errln("ERROR: parse() failed");
+             fail("ERROR: parse() failed");
          }
-         logln(text + " parsed into " + result2);
+         System.out.println(text + " parsed into " + result2);
  
          // ======= Test getters and setters
  
-         logln("Testing getters and setters");
+         System.out.println("Testing getters and setters");
  
          final DateFormatSymbols syms = pat.getDateFormatSymbols();
          def.setDateFormatSymbols(syms);
          pat_fr.setDateFormatSymbols(syms);
          if( ! pat.getDateFormatSymbols().equals(def.getDateFormatSymbols()) ) {
-             errln("ERROR: set DateFormatSymbols() failed");
+             fail("ERROR: set DateFormatSymbols() failed");
          }
  
          Date startDate = null;
          try {
  //            startDate = pat.getTwoDigitStartDate();
          }
          catch (Exception e) {
-             errln("ERROR: getTwoDigitStartDate() failed");
+             fail("ERROR: getTwoDigitStartDate() failed");
          }
  
          try {
  //            pat_fr.setTwoDigitStartDate(startDate);
          }
          catch (Exception e) {
-             errln("ERROR: setTwoDigitStartDate() failed");
+             fail("ERROR: setTwoDigitStartDate() failed");
          }
  
          // ======= Test applyPattern()
  
-         logln("Testing applyPattern()");
+         System.out.println("Testing applyPattern()");
  
          String p1 = new String("yyyy.MM.dd G 'at' hh:mm:ss z");
-         logln("Applying pattern " + p1);
+         System.out.println("Applying pattern " + p1);
          pat.applyPattern(p1);
  
          String s2 = pat.toPattern();
-         logln("Extracted pattern is " + s2);
+         System.out.println("Extracted pattern is " + s2);
          if( ! s2.equals(p1) ) {
-             errln("ERROR: toPattern() result did not match pattern applied");
+             fail("ERROR: toPattern() result did not match pattern applied");
          }
  
-         logln("Applying pattern " + p1);
+         System.out.println("Applying pattern " + p1);
          pat.applyLocalizedPattern(p1);
          String s3 = pat.toLocalizedPattern();
-         logln("Extracted pattern is " + s3);
+         System.out.println("Extracted pattern is " + s3);
          if( ! s3.equals(p1) ) {
-             errln("ERROR: toLocalizedPattern() result did not match pattern applied");
+             fail("ERROR: toLocalizedPattern() result did not match pattern applied");
          }
  
          // ======= Test getStaticClassID()
  
  //        logln("Testing instanceof");
< prev index next >