< prev index next >

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

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1997, 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.

@@ -24,53 +24,55 @@
  /**
   * @test
   * @bug 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571
   *      8190748 8216969
   * @summary test DateFormat and SimpleDateFormat.
-  * @library /java/text/testlib
   * @modules jdk.localedata
-  * @run main/othervm -Djava.locale.providers=COMPAT,SPI DateFormatTest
+  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI DateFormatTest
   */
  
  import java.util.*;
  import java.text.*;
  import static java.util.GregorianCalendar.*;
  
- public class DateFormatTest extends IntlTest
+ import org.junit.jupiter.api.Test;
+ import org.junit.jupiter.api.BeforeAll;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class DateFormatTest
  {
-     public static void main(String[] args) throws Exception {
-         Locale reservedLocale = Locale.getDefault();
-         try {
-             Locale.setDefault(Locale.US);
-             new DateFormatTest().run(args);
-         } finally {
-             // restore the reserved locale
-             Locale.setDefault(reservedLocale);
-         }
+ 
+     // Change JVM default Locale
+     @BeforeAll
+     static void initAll() {
+         Locale.setDefault(Locale.US);
      }
  
      // Test 4 digit year parsing with pattern "yy"
      @SuppressWarnings("deprecation")
+     @Test
      public void TestYearParsing()
      {
          String str = "7/Sep/2001";
          Date exp = new Date(2001-1900, SEPTEMBER, 7);
          String pat = "d/MMM/yy";
          SimpleDateFormat sdf = new SimpleDateFormat(pat, Locale.US);
          try {
              Date d = sdf.parse(str);
-             logln(str + " parses with " + pat + " to " + d);
+             System.out.println(str + " parses with " + pat + " to " + d);
              if (d.getTime() != exp.getTime()) {
-                 errln("FAIL: Expected " + exp);
+                 fail("FAIL: Expected " + exp);
              }
          }
          catch (ParseException e) {
-             errln(str + " parse fails with " + pat);
+             fail(str + " parse fails with " + pat);
          }
      }
  
      // Test written by Wally Wedel and emailed to me.
+     @Test
      public void TestWallyWedel()
      {
          /*
           * Instantiate a TimeZone so we can get the ids.
           */

@@ -89,15 +91,15 @@
           */
          String[] ids = TimeZone.getAvailableIDs();
          /*
           * How many ids do we have?
           */
-         logln("Time Zone IDs size: " + ids.length);
+         System.out.println("Time Zone IDs size: " + ids.length);
          /*
           * Column headings (sort of)
           */
-         logln("Ordinal ID offset(h:m) name");
+         System.out.println("Ordinal ID offset(h:m) name");
          /*
           * Loop through the tzs.
           */
          Date today = new Date();
          Calendar cal = Calendar.getInstance();

@@ -134,36 +136,38 @@
               * Show our result.
               */
              boolean ok = fmtDstOffset == null || fmtDstOffset.equals(dstOffset);
              if (ok)
              {
-                 logln(i + " " + ids[i] + " " + dstOffset +
+                 System.out.println(i + " " + ids[i] + " " + dstOffset +
                        " " + fmtOffset +
                        (fmtDstOffset != null ? " ok" : " ?"));
              }
              else
              {
-                 errln(i + " " + ids[i] + " " + dstOffset +
+                 fail(i + " " + ids[i] + " " + dstOffset +
                        " " + fmtOffset + " *** FAIL ***");
              }
          }
      }
  
      // Test equals
+     @Test
      public void TestEquals()
      {
          DateFormat fmtA = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
  
          DateFormat fmtB = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
  
          if (!fmtA.equals(fmtB)) {
-             errln("FAIL");
+             fail("FAIL");
          }
      }
  
      // Check out some specific parsing problem
      @SuppressWarnings("deprecation")
+     @Test
      public void TestTwoDigitYearDSTParse()
      {
          SimpleDateFormat fullFmt =
              new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
  

@@ -179,16 +183,16 @@
          String s = "03-Apr-04 2:20:47 o'clock AM PST";
          int hour = 2;
          try {
              TimeZone.setDefault(PST);
              Date d = fmt.parse(s);
-             logln(s + " P> " + fullFmt.format(d));
+             System.out.println(s + " P> " + fullFmt.format(d));
              if (d.getHours() != hour) {
-                 errln("FAIL: Should parse to hour " + hour);
+                 fail("FAIL: Should parse to hour " + hour);
              }
          }
-         catch (ParseException e) { errln("FAIL: " + e.getMessage()); }
+         catch (ParseException e) { fail("FAIL: " + e.getMessage()); }
          finally {
              TimeZone.setDefault(save);
          }
      }
  

@@ -232,10 +236,11 @@
      };
  
      /**
       * Bug 4089987
       */
+     @Test
      public void TestFieldPosition()
      {
          DateFormat[] dateFormats = {
              DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,
                                             Locale.US),

@@ -271,17 +276,17 @@
              DateFormat df = dateFormats[j];
              if (!(df instanceof SimpleDateFormat)) {
                  continue;
              }
              df.setTimeZone(PST);
-             logln(" Pattern = " + ((SimpleDateFormat)df).toPattern());
-             logln("  Result = " + df.format(someDate));
+             System.out.println(" Pattern = " + ((SimpleDateFormat)df).toPattern());
+             System.out.println("  Result = " + df.format(someDate));
              for (int i = 0; i < fieldIDs.length; ++i)
              {
                  String field = getFieldText(df, fieldIDs[i], someDate);
                  if (!field.equals(expected[exp])) {
-                     errln("FAIL: field #" + i + " " + fieldNames[i] + " = \"" +
+                     fail("FAIL: field #" + i + " " + fieldNames[i] + " = \"" +
                              escape(field) + "\", expected \"" + escape(expected[exp]) + "\"");
                  }
                  ++exp;
              }
          }

@@ -296,10 +301,11 @@
                                             pos.getEndIndex());
      }
  
      // Test parsing of partial strings
      @SuppressWarnings("deprecation")
+     @Test
      public void TestPartialParse994()
      {
          SimpleDateFormat f = new SimpleDateFormat();
          Calendar cal = new GregorianCalendar(2014 - 80, JANUARY, 1);
          f.set2DigitYearStart(cal.getTime());

@@ -310,68 +316,70 @@
          tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17", null);
      }
  
      void tryPat994(SimpleDateFormat format, String pat, String str, Date expected)
      {
-         logln("Pattern \"" + pat + "\"   String \"" + str + "\"");
+         System.out.println("Pattern \"" + pat + "\"   String \"" + str + "\"");
          try {
              format.applyPattern(pat);
              Date date = format.parse(str);
              String f = format.format(date);
-             logln(" parse(" + str + ") -> " + date.toString());
-             logln(" format -> " + f);
+             System.out.println(" parse(" + str + ") -> " + date.toString());
+             System.out.println(" format -> " + f);
              if (expected == null ||
                  !date.equals(expected)) {
-                 errln("FAIL: Expected " + expected);
+                 fail("FAIL: Expected " + expected);
              }
              if (!f.equals(str)) {
-                 errln("FAIL: Expected " + str);
+                 fail("FAIL: Expected " + str);
              }
          }
          catch(ParseException e) {
-             logln("ParseException: " + e.getMessage());
+             System.out.println("ParseException: " + e.getMessage());
              if (expected != null) {
-                 errln("FAIL: Expected " + expected);
+                 fail("FAIL: Expected " + expected);
              }
          }
          catch(Exception e) {
-             errln("*** Exception:");
+             fail("*** Exception:");
              e.printStackTrace();
          }
      }
  
      // Test pattern with runs things together
+     @Test
      public void TestRunTogetherPattern985()
      {
          String format = "yyyyMMddHHmmssSSSzzzz";
          String now, then;
  
          SimpleDateFormat formatter = new SimpleDateFormat(format);
  
          Date date1 = new Date();
          now = formatter.format(date1);
  
-         logln(now);
+         System.out.println(now);
  
          ParsePosition pos = new ParsePosition(0);
  
          Date date2 = formatter.parse(now, pos);
          if (date2 == null) {
              then = "Parse stopped at " + pos.getIndex();
          } else {
              then = formatter.format(date2);
          }
  
-         logln(then);
+         System.out.println(then);
  
          if (!date2.equals(date1)) {
-             errln("FAIL");
+             fail("FAIL");
          }
      }
  
      // Test patterns which run numbers together
      @SuppressWarnings("deprecation")
+     @Test
      public void TestRunTogetherPattern917()
      {
          SimpleDateFormat fmt;
          String myDate;
  

@@ -384,107 +392,110 @@
          _testIt917( fmt, myDate, new Date(97, 3-1, 4) );
  
      }
      void _testIt917( SimpleDateFormat fmt, String str, Date expected )
      {
-         logln( "pattern=" + fmt.toPattern() + "   string=" + str );
+         System.out.println( "pattern=" + fmt.toPattern() + "   string=" + str );
  
          Object o;
          try {
              o = fmt.parseObject( str );
          } catch( ParseException e ) {
              e.printStackTrace();
              return;
          }
-         logln( "Parsed object: " + o );
+         System.out.println( "Parsed object: " + o );
          if (!o.equals(expected)) {
-             errln("FAIL: Expected " + expected);
+             fail("FAIL: Expected " + expected);
          }
  
          String formatted = fmt.format( o );
-         logln( "Formatted string: " + formatted );
+         System.out.println( "Formatted string: " + formatted );
          if (!formatted.equals(str)) {
-             errln("FAIL: Expected " + str);
+             fail("FAIL: Expected " + str);
          }
      }
  
      // Test Czech month formatting -- this can cause a problem because the June and
      // July month names share a common prefix.
      @SuppressWarnings("deprecation")
+     @Test
      public void TestCzechMonths459()
      {
          // Use Czech, which has month names with shared prefixes for June and July
          DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, Locale.of("cs"));
          //((SimpleDateFormat)fmt).applyPattern("MMMM d yyyy");
-         logln("Pattern " + ((SimpleDateFormat)fmt).toPattern());
+         System.out.println("Pattern " + ((SimpleDateFormat)fmt).toPattern());
  
          Date june = new Date(97, Calendar.JUNE, 15);
          Date july = new Date(97, Calendar.JULY, 15);
  
          String juneStr = fmt.format(june);
          String julyStr = fmt.format(july);
  
          try {
-             logln("format(June 15 1997) = " + juneStr);
+             System.out.println("format(June 15 1997) = " + juneStr);
              Date d = fmt.parse(juneStr);
              String s = fmt.format(d);
              int month = d.getMonth();
-             logln("  -> parse -> " + s + " (month = " + month + ")");
+             System.out.println("  -> parse -> " + s + " (month = " + month + ")");
              if (month != JUNE) {
-                 errln("FAIL: Month should be June");
+                 fail("FAIL: Month should be June");
              }
  
-             logln("format(July 15 1997) = " + julyStr);
+             System.out.println("format(July 15 1997) = " + julyStr);
              d = fmt.parse(julyStr);
              s = fmt.format(d);
              month = d.getMonth();
-             logln("  -> parse -> " + s + " (month = " + month + ")");
+             System.out.println("  -> parse -> " + s + " (month = " + month + ")");
              if (month != JULY) {
-                 errln("FAIL: Month should be July");
+                 fail("FAIL: Month should be July");
              }
          }
          catch (ParseException e) {
-             errln("Exception: " + e);
+             fail("Exception: " + e);
          }
      }
  
      // Test big D (day of year) versus little d (day of month)
      @SuppressWarnings("deprecation")
+     @Test
      public void TestLetterDPattern212()
      {
          String dateString = "1995-040.05:01:29";
          String bigD = "yyyy-DDD.hh:mm:ss";
          String littleD = "yyyy-ddd.hh:mm:ss";
          Date expLittleD = new Date(95, 0, 1, 5, 1, 29);
          Date expBigD =  new Date(expLittleD.getTime() + 39*24*3600000L); // 39 days
          expLittleD = expBigD; // Expect the same, with default lenient parsing
-         logln( "dateString= " + dateString );
+         System.out.println( "dateString= " + dateString );
          SimpleDateFormat formatter = new SimpleDateFormat(bigD);
          ParsePosition pos = new ParsePosition(0);
          Date myDate = formatter.parse( dateString, pos );
-         logln("Using " + bigD + " -> " + myDate);
+         System.out.println("Using " + bigD + " -> " + myDate);
          if (myDate.getTime() != expBigD.getTime()) {
-             errln("FAIL: Expected " + expBigD + " got " + myDate);
+             fail("FAIL: Expected " + expBigD + " got " + myDate);
          }
  
          formatter = new SimpleDateFormat(littleD);
          pos = new ParsePosition(0);
          myDate = formatter.parse( dateString, pos );
-         logln("Using " + littleD + " -> " + myDate);
+         System.out.println("Using " + littleD + " -> " + myDate);
          if (myDate.getTime() != expLittleD.getTime()) {
-             errln("FAIL: Expected " + expLittleD + " got " + myDate);
+             fail("FAIL: Expected " + expLittleD + " got " + myDate);
          }
      }
  
      // Test the 'G' day of year pattern
      @SuppressWarnings("deprecation")
+     @Test
      public void TestDayOfYearPattern195()
      {
          Date today = new Date();
          Date expected = new Date(today.getYear(), today.getMonth(), today.getDate());
  
-         logln("Test Date: " + today);
+         System.out.println("Test Date: " + today);
  
          SimpleDateFormat sdf =
              (SimpleDateFormat)SimpleDateFormat.getDateInstance();
  
          tryPattern(sdf, today, null, expected);

@@ -494,43 +505,44 @@
      void tryPattern(SimpleDateFormat sdf, Date d, String pattern, Date expected)
      {
          if (pattern != null) {
              sdf.applyPattern(pattern);
          }
-         logln("pattern: " + sdf.toPattern());
+         System.out.println("pattern: " + sdf.toPattern());
  
          String formatResult = sdf.format(d);
-         logln(" format -> " + formatResult);
+         System.out.println(" format -> " + formatResult);
          try {
              Date d2 = sdf.parse(formatResult);
-             logln(" parse(" + formatResult +  ") -> " + d2);
+             System.out.println(" parse(" + formatResult +  ") -> " + d2);
              if (d2.getTime() != expected.getTime()) {
-                 errln("FAIL: Expected " + expected);
+                 fail("FAIL: Expected " + expected);
              }
              String format2 = sdf.format(d2);
-             logln(" format -> " + format2);
+             System.out.println(" format -> " + format2);
              if (!formatResult.equals(format2)) {
-                 errln("FAIL: Round trip drift");
+                 fail("FAIL: Round trip drift");
              }
          }
          catch(Exception e) {
-             errln("Error: " + e.getMessage());
+             fail("Error: " + e.getMessage());
          }
      }
  
      // Test a pattern with single quotes
      @SuppressWarnings("deprecation")
+     @Test
      public void TestQuotePattern161()
      {
          // This pattern used to end in " zzz" but that makes this test zone-dependent
          SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy 'at' hh:mm:ss a zzz");
          Date currentTime_1 = new Date(97, Calendar.AUGUST, 13, 10, 42, 28);
          String dateString = formatter.format(currentTime_1);
          String exp = "08/13/1997 at 10:42:28 AM ";
-         logln("format(" + currentTime_1 + ") = " + dateString);
+         System.out.println("format(" + currentTime_1 + ") = " + dateString);
          if (!dateString.regionMatches(0, exp, 0, exp.length())) {
-             errln("FAIL: Expected " + exp);
+             fail("FAIL: Expected " + exp);
          }
      }
  
      // Test the parsing of bad input strings
      /** Demonstrates a number of bugs in DateFormat.parse(String) where

@@ -538,10 +550,11 @@
       *  returned instead of ParseException. To reproduce, run this program
       *  and notice all the "SHOULD NOT HAPPEN" errors.  Note also that the
       *  1 line that should be correct is off by 100 years.  (In this day
       *  and age, no one would assume that 1/1/00 is Jan 1 1900.)
       **/
+     @Test
      public void TestBadInput135()
      {
          int        looks[] = { DateFormat.SHORT, DateFormat.MEDIUM,
                                 DateFormat.LONG,  DateFormat.FULL };
          String     strings[] = { "Mar 15", "Mar 15 1997", "asdf",

@@ -558,26 +571,26 @@
                      DateFormat df = DateFormat.getDateTimeInstance(dateLook, timeLook);
                      String prefix = text + ", " + dateLook + "/" + timeLook + ": ";
                      try {
                          Date when = df.parse(text);
                          if ( when == null ){
-                             errln(prefix +
+                             fail(prefix +
                                    "SHOULD NOT HAPPEN: parse returned null.");
                              continue;
                          }
                          String format = full.format(when);
-                         logln(prefix + "OK: " + format);
+                         System.out.println(prefix + "OK: " + format);
                          // Only match the start -- not the zone, which could vary
                          if (!format.regionMatches(0, expected, 0, expected.length())) {
-                             errln("FAIL: Expected " + expected);
+                             fail("FAIL: Expected " + expected);
                          }
                      }
                      catch ( ParseException e ){
                          //errln(prefix + e); // This is expected.
                      }
                      catch ( StringIndexOutOfBoundsException e ){
-                         errln(prefix + "SHOULD NOT HAPPEN: " + e);
+                         fail(prefix + "SHOULD NOT HAPPEN: " + e);
                      }
                  }
              }
          }
      }

@@ -608,26 +621,27 @@
          "1",                    null, null, null, null, null, null, null, "0001", null, // Bug620
          "3:00 pm Jan 1, 1997",  null, null, null, null, null, null, null, "0003", "3:00 PM January 1, 1997",
      };
      // More testing of the parsing of bad input
      @SuppressWarnings("UnusedAssignment")
+     @Test
      public void TestBadInput135a()
      {
          SimpleDateFormat dateParse = new SimpleDateFormat();
          String s;
          Date date;
          int PFLENGTH = parseFormats.length;
  
          dateParse.applyPattern("d MMMM, yyyy");
          dateParse.setTimeZone(TimeZone.getDefault());
          s = "not parseable";
-         logln("Trying to parse \"" + s + "\" with " + dateParse.toPattern());
+         System.out.println("Trying to parse \"" + s + "\" with " + dateParse.toPattern());
          try {
              date = dateParse.parse(s);
-             errln("FAIL: Expected exception during parse");
+             fail("FAIL: Expected exception during parse");
          } catch (Exception ex) {
-             logln("Exception during parse: " + ex); // This is expected
+             System.out.println("Exception during parse: " + ex); // This is expected
          }
  
          for (int i=0; i<inputStrings.length; i += (PFLENGTH+1))
          {
              ParsePosition parsePosition = new ParsePosition(0);

@@ -642,38 +656,39 @@
                  try {
                      parsePosition.setIndex(0);
                      date = dateParse.parse(s, parsePosition);
                      if (parsePosition.getIndex() != 0) {
                          if (date == null) {
-                             errln("ERROR: null result with pos " +
+                             fail("ERROR: null result with pos " +
                                      parsePosition.getIndex() + " " +
                                      s.substring(0, parsePosition.getIndex()) + "|" +
                                      s.substring(parsePosition.getIndex()));
                          } else {
                              String result = dateParse.format(date);
-                             logln("Parsed \"" + s + "\" using \"" + dateParse.toPattern() +
+                             System.out.println("Parsed \"" + s + "\" using \"" + dateParse.toPattern() +
                                    "\" to: " + result);
                              if (expected == null) {
-                                 errln("FAIL: Expected parse failure");
+                                 fail("FAIL: Expected parse failure");
                              } else if (!expected.equals(result)) {
-                                 errln("FAIL: Expected " + expected);
+                                 fail("FAIL: Expected " + expected);
                              }
                          }
                      } else {
                          // logln("Not parsed.");
                          if (expected != null) {
-                             errln("FAIL: Expected " + expected);
+                             fail("FAIL: Expected " + expected);
                          }
                      }
                  } catch (Exception ex) {
-                     errln("An exception was thrown during parse: " + ex);
+                     fail("An exception was thrown during parse: " + ex);
                  }
              }
          }
      }
  
      // Test the handling of 2-digit dates
+     @Test
      public void TestTwoDigitYear() {
          SimpleDateFormat fmt = new SimpleDateFormat("M/d/yy");
  
          // find out the expected 2-digit year values for "6/5/17" and "6/4/34"
          long start = fmt.get2DigitYearStart().getTime();

@@ -693,14 +708,14 @@
              if (xx17 != 0 && xx34 != 0) {
                  break;
              }
          }
          if (xx17 == 0 || xx34 == 0) {
-             errln("Failed: producing expected values: 2DigitYearStart: " + new Date(start)
+             fail("Failed: producing expected values: 2DigitYearStart: " + new Date(start)
                    + ", xx17 = " + xx17 + ", xx34 = " + xx34);
          }
-         logln("2DigitYearStart: " + new Date(start) + ", xx17 = " + xx17 + ", xx34 = " + xx34);
+         System.out.println("2DigitYearStart: " + new Date(start) + ", xx17 = " + xx17 + ", xx34 = " + xx34);
  
          parse2DigitYear(fmt, "6/5/17", new GregorianCalendar(xx17, JUNE, 5).getTime());
          parse2DigitYear(fmt, "6/4/34", new GregorianCalendar(xx34, JUNE, 4).getTime());
      }
  

@@ -711,51 +726,53 @@
      }
  
      private void parse2DigitYear(SimpleDateFormat fmt, String str, Date expected) {
          try {
              Date d = fmt.parse(str);
-             logln("Parsing \"" + str + "\" with " +
+             System.out.println("Parsing \"" + str + "\" with " +
                    fmt.toPattern() +
                    "  => " + d.toString());
              if (d.getTime() != expected.getTime()) {
-                 errln("FAIL: Expected " + expected);
+                 fail("FAIL: Expected " + expected);
              }
          } catch (ParseException e) {
-             errln("FAIL: Got exception");
+             fail("FAIL: Got exception");
          }
      }
  
      // Test behavior of DateFormat with applied time zone
+     @Test
      public void TestDateFormatZone061()
      {
          Date date;
          DateFormat formatter;
  
          // 25-Mar-97 00:00:00 GMT
          date = new Date( 859248000000L );
-         logln( "Date 1997/3/25 00:00 GMT: " + date );
+         System.out.println( "Date 1997/3/25 00:00 GMT: " + date );
          formatter = new SimpleDateFormat("dd-MMM-yyyyy HH:mm", Locale.UK);
          formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
  
          String temp = formatter.format( date );
-         logln( "Formatted in GMT to: " + temp );
+         System.out.println( "Formatted in GMT to: " + temp );
  
          /* Parse date string */
          try {
              Date tempDate = formatter.parse( temp );
-             logln( "Parsed to: " + tempDate );
+             System.out.println( "Parsed to: " + tempDate );
              if (tempDate.getTime() != date.getTime()) {
-                 errln("FAIL: Expected " + date);
+                 fail("FAIL: Expected " + date);
              }
          }
          catch( Throwable t ) {
-             errln( "Date Formatter throws: " +
+             fail( "Date Formatter throws: " +
                     t.toString() );
          }
      }
  
      // Make sure DateFormat uses the correct zone.
+     @Test
      public void TestDateFormatZone146()
      {
          TimeZone saveDefault = TimeZone.getDefault();
  
          try {

@@ -765,13 +782,13 @@
  
              // check to be sure... its GMT all right
              TimeZone testdefault = TimeZone.getDefault();
              String testtimezone = testdefault.getID();
              if (testtimezone.equals("GMT")) {
-                 logln("Test timezone = " + testtimezone);
+                 System.out.println("Test timezone = " + testtimezone);
              } else {
-                 errln("Test timezone should be GMT, not " + testtimezone);
+                 fail("Test timezone should be GMT, not " + testtimezone);
              }
  
              // now try to use the default GMT time zone
              GregorianCalendar greenwichcalendar =
                  new GregorianCalendar(1997, 3, 4, 23, 0);

@@ -797,53 +814,55 @@
  
              for (int i=0; i<DATA.length; i+=3) {
                  DateFormat fmt = new SimpleDateFormat(DATA[i+2], Locale.ENGLISH);
                  fmt.setCalendar(greenwichcalendar);
                  String result = fmt.format(greenwichdate);
-                 logln(DATA[i] + result);
+                 System.out.println(DATA[i] + result);
                  if (!result.equals(DATA[i+1])) {
-                     errln("FAIL: Expected " + DATA[i+1]
+                     fail("FAIL: Expected " + DATA[i+1]
                              + ", got " + result);
                  }
              }
          }
          finally {
              TimeZone.setDefault(saveDefault);
          }
      }
  
  /* HS : Commented out for now, need to be changed not to use hardcoded results.
+     @Test
      public void TestLocaleDateFormat() // Bug 495
      {
          Date testDate = new Date (97, Calendar.SEPTEMBER, 15);
          DateFormat dfFrench = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                               DateFormat.FULL, Locale.FRENCH);
          DateFormat dfUS = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                           DateFormat.FULL, Locale.US);
          String expectedFRENCH = "lundi 15 septembre 1997 00 h 00 GMT-07:00";
          String expectedUS = "Monday, September 15, 1997 12:00:00 o'clock AM PDT";
-         logln("Date set to : " + testDate);
+         System.out.println("Date set to : " + testDate);
          String out = dfFrench.format(testDate);
-         logln("Date Formated with French Locale " + out);
-         if (!out.equals(expectedFRENCH)) errln("FAIL: Expected " + expectedFRENCH);
+         System.out.println("Date Formated with French Locale " + out);
+         if (!out.equals(expectedFRENCH)) fail("FAIL: Expected " + expectedFRENCH);
          out = dfUS.format(testDate);
-         logln("Date Formated with US Locale " + out);
-         if (!out.equals(expectedUS)) errln("FAIL: Expected " + expectedUS);
+         System.out.println("Date Formated with US Locale " + out);
+         if (!out.equals(expectedUS)) fail("FAIL: Expected " + expectedUS);
      }
  */
      /**
       * Bug 4056591
       */
  /*
  test commented out pending API-change approval
+     @Test
      public void Test2YearStartDate() throws ParseException
      {
          // create a SimpleDateFormat to test with; dump out if it's not a SimpleDateFormat
          DateFormat test = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
  
          if (!(test instanceof SimpleDateFormat)) {
-             errln("DateFormat.getInstance() didn't return an instance of SimpleDateFormat!");
+             fail("DateFormat.getInstance() didn't return an instance of SimpleDateFormat!");
              return;
          }
  
          SimpleDateFormat sdf = (SimpleDateFormat)test;
          String testString1 = "3/10/67";

@@ -859,153 +878,156 @@
          // set2DigitStartDate()
          Date date = sdf.get2DigitStartDate();
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1900 || cal.get(Calendar.MONTH) != 0 ||
                          cal.get(Calendar.DATE) != 1)
-             errln("SimpleDateFormat.get2DigitStartDate() returned " + (cal.get(Calendar.MONTH)
+             fail("SimpleDateFormat.get2DigitStartDate() returned " + (cal.get(Calendar.MONTH)
                          + 1) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR) +
                          " instead of 1/1/1900.");
  
          // try parsing "3/10/67" and "3/16/43" with the 2-digit start date set to 1/1/1900
          date = sdf.parse(testString1);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1967)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1900 yielded a year of "
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1900 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1967.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 10)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1900 failed: got " +
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1900 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/10.");
          date = sdf.parse(testString2);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1943)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1900 yielded a year of "
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1900 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1943.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 16)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1900 failed: got " +
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1900 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/16.");
  
          // try parsing "3/10/67" and "3/16/43" with the 2-digit start date set to 1/1/2000
          cal.set(2000, 0, 1);
          sdf.set2DigitStartDate(cal.getTime());
          date = sdf.parse(testString1);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 2067)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/2000 yielded a year of "
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/2000 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 2067.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 10)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/2000 failed: got " +
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/2000 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/10.");
          date = sdf.parse(testString2);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 2043)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/2000 yielded a year of "
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/2000 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1943.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 16)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/2000 failed: got " +
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/2000 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/16.");
  
          // try parsing "3/10/67" and "3/16/43" with the 2-digit start date set to 1/1/1950
          cal.set(1950, 0, 1);
          sdf.set2DigitStartDate(cal.getTime());
          date = sdf.parse(testString1);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1967)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1950 yielded a year of "
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1950 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1967.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 10)
-             errln("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1950 failed: got " +
+             fail("Parsing \"3/10/67\" with 2-digit start date set to 1/1/1950 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/10.");
          date = sdf.parse(testString2);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 2043)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1950 yielded a year of "
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1950 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1943.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 16)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1950 failed: got " +
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 1/1/1950 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/16.");
  
          // try parsing "3/16/43" and "7/21/43" with the 2-digit start date set to 6/1/1943
          cal.set(1943, 5, 1);
          sdf.set2DigitStartDate(cal.getTime());
          date = sdf.parse(testString2);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 2043)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 6/1/1943 yielded a year of "
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 6/1/1943 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 2043.");
          if (cal.get(Calendar.MONTH) != 2 || cal.get(Calendar.DATE) != 16)
-             errln("Parsing \"3/16/43\" with 2-digit start date set to 6/1/1943 failed: got " +
+             fail("Parsing \"3/16/43\" with 2-digit start date set to 6/1/1943 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 3/16.");
          date = sdf.parse(testString3);
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1943)
-             errln("Parsing \"7/21/43\" with 2-digit start date set to 6/1/1943 yielded a year of "
+             fail("Parsing \"7/21/43\" with 2-digit start date set to 6/1/1943 yielded a year of "
                              + cal.get(Calendar.YEAR) + " instead of 1943.");
          if (cal.get(Calendar.MONTH) != 6 || cal.get(Calendar.DATE) != 21)
-             errln("Parsing \"7/21/43\" with 2-digit start date set to 6/1/1943 failed: got " +
+             fail("Parsing \"7/21/43\" with 2-digit start date set to 6/1/1943 failed: got " +
                              (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) +
                              " instead of 7/21.");
  
          // and finally, check one more time to make sure get2DigitStartDate() returns the last
          // value we passed to set2DigitStartDate()
          date = sdf.get2DigitStartDate();
          cal.setTime(date);
          if (cal.get(Calendar.YEAR) != 1943 || cal.get(Calendar.MONTH) != 5 ||
                          cal.get(Calendar.DATE) != 1)
-             errln("SimpleDateFormat.get2DigitStartDate() returned " + (cal.get(Calendar.MONTH)
+             fail("SimpleDateFormat.get2DigitStartDate() returned " + (cal.get(Calendar.MONTH)
                          + 1) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR) +
                          " instead of 6/1/1943.");
      }
  */
  
      /**
       * ParsePosition.errorIndex tests.
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4052223()
      {
          String str = "7/SOS/2001";
          Date exp = new Date(101, Calendar.SEPTEMBER, 7);
          String pat = "d/MMM/yy";
          SimpleDateFormat sdf = new SimpleDateFormat(pat);
          ParsePosition pos = new ParsePosition(0);
          Date d = sdf.parse(str, pos);
-         logln(str + " parses with " + pat + " to " + d);
+         System.out.println(str + " parses with " + pat + " to " + d);
          if (d == null && pos.getErrorIndex() == 2) {
-             logln("Expected null returned, failed at : " + pos.getErrorIndex());
+             System.out.println("Expected null returned, failed at : " + pos.getErrorIndex());
          } else {
-             errln("Failed, parse " + str + " got : " + d + ", index=" + pos.getErrorIndex());
+             fail("Failed, parse " + str + " got : " + d + ", index=" + pos.getErrorIndex());
          }
      }
  
      /**
       * Bug4469904 -- th_TH date format doesn't use Thai B.E.
       */
+     @Test
      public void TestBuddhistEraBugId4469904() {
          String era = "\u0e1e.\u0e28.";
          Locale loc = Locale.of("th", "TH");
          Calendar cal = Calendar.getInstance(Locale.US);
          cal.set(2001, 7, 23);
          Date date = cal.getTime();
          DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, loc);
          String output = df.format(date);
          int index = output.indexOf(era);
          if (index == -1) {
-             errln("Test4469904: Failed. Buddhist Era abbrev not present.");
+             fail("Test4469904: Failed. Buddhist Era abbrev not present.");
          }
      }
  
      /**
       * 4326988: API: SimpleDateFormat throws NullPointerException when parsing with null pattern
       */
      @SuppressWarnings("UnusedAssignment")
+     @Test
      public void Test4326988() {
          String[] wrongPatterns = {
              "hh o''clock",
              "hh 'o''clock",     // unterminated quote
              "''''''''''''oclock",

@@ -1019,65 +1041,65 @@
          };
  
          // Check NullPointerException
          try {
              SimpleDateFormat fmt = new SimpleDateFormat(null);
-             errln("SimpleDateFormat() doesn't throw NPE with null pattern");
+             fail("SimpleDateFormat() doesn't throw NPE with null pattern");
          } catch (NullPointerException e) {
              // Okay
          }
          try {
              Locale loc = null;
              SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd", loc);
-             errln("SimpleDateFormat() doesn't throw NPE with null locale");
+             fail("SimpleDateFormat() doesn't throw NPE with null locale");
          } catch (NullPointerException e) {
              // Okay
          }
          try {
              DateFormatSymbols symbols = null;
              SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd", symbols);
-             errln("SimpleDateFormat() doesn't throw NPE with null DateFormatSymbols");
+             fail("SimpleDateFormat() doesn't throw NPE with null DateFormatSymbols");
          } catch (NullPointerException e) {
              // Okay
          }
          try {
              SimpleDateFormat fmt = new SimpleDateFormat();
              fmt.applyPattern(null);
-             errln("applyPattern() doesn't throw NPE with null pattern");
+             fail("applyPattern() doesn't throw NPE with null pattern");
          } catch (NullPointerException e) {
              // Okay
          }
  
          // Check IllegalParameterException
          for (int i = 0; i < wrongPatterns.length; i++) {
              try {
                  SimpleDateFormat fmt = new SimpleDateFormat(wrongPatterns[i]);
-                 errln("SimpleDateFormat(\"" + wrongPatterns[i] + "\")" +
+                 fail("SimpleDateFormat(\"" + wrongPatterns[i] + "\")" +
                        " doesn't throw an IllegalArgumentException");
              } catch (IllegalArgumentException e) {
                  // Okay
              }
              try {
                  SimpleDateFormat fmt = new SimpleDateFormat(wrongPatterns[i],
                                                              DateFormatSymbols.getInstance());
-                 errln("SimpleDateFormat(\"" + wrongPatterns[i] + "\", DateFormatSymbols) doesn't " +
+                 fail("SimpleDateFormat(\"" + wrongPatterns[i] + "\", DateFormatSymbols) doesn't " +
                        "throw an IllegalArgumentException");
              } catch (IllegalArgumentException e) {
                  // Okay
              }
              try {
                  SimpleDateFormat fmt = new SimpleDateFormat(wrongPatterns[i],
                                                              Locale.US);
-                 errln("SimpleDateFormat(\"" + wrongPatterns[i] +
+                 fail("SimpleDateFormat(\"" + wrongPatterns[i] +
                        "\", Locale) doesn't throw an IllegalArgumentException");
              } catch (IllegalArgumentException e) {
                  // Okay
              }
              try {
                  SimpleDateFormat fmt = new SimpleDateFormat();
                  fmt.applyPattern(wrongPatterns[i]);
-                 errln("SimpleDateFormat.applyPattern(\"" + wrongPatterns[i] +
+                 fail("SimpleDateFormat.applyPattern(\"" + wrongPatterns[i] +
                        "\") doesn't throw an IllegalArgumentException");
              } catch (IllegalArgumentException e) {
                  // Okay
              }
          }

@@ -1098,31 +1120,32 @@
       * 4486735: RFE: SimpleDateFormat performance improvement
       *
       * Another round trip test
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void Test4486735() throws Exception {
          TimeZone initialTimeZone = TimeZone.getDefault();
          TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
          Locale[] locales = Locale.getAvailableLocales();
          String[] zones = { "GMT", "America/Los_Angeles", "Europe/London", "Asia/Tokyo" };
  
          // Round to minutes. Some FULL formats don't have seconds.
          long time = System.currentTimeMillis()/60000 * 60000;
          Date date = new Date(time);
-         logln("the test date: " + date);
+         System.out.println("the test date: " + date);
  
          try {
              for (int z = 0; z < zones.length; z++) {
                  TimeZone.setDefault(TimeZone.getTimeZone(zones[z]));
                  for (int i = 0; i < locales.length; i++) {
                      Locale loc = locales[i];
                      DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                                     DateFormat.FULL,
                                                                     loc);
                      String s = df.format(date);
-                     logln(s);
+                     System.out.println(s);
                      Date parsedDate = df.parse(s);
                      long parsedTime = parsedDate.getTime();
                      if (time != parsedTime) {
                          // See if the time is in daylight-standard time transition. (JDK-8140571)
                          // Date-time formats in some locales don't have time zone information.

@@ -1131,11 +1154,11 @@
                              if (time == parsedTime - tz.getDSTSavings()) {
                                  // OK (in "fall-back")
                                  continue;
                              }
                          }
-                         errln("round trip conversion failed: timezone="+zones[z]+
+                         fail("round trip conversion failed: timezone="+zones[z]+
                                ", locale=" + loc +
                                ", expected=" + time + ", got=" + parsedTime);
                      }
                  }
              }

@@ -1189,26 +1212,27 @@
                  "00000000000000000000000000000000000000000000000000" +
                  "00000000000000000000000000000000000000000000002001\u5e74";
              SimpleDateFormat sdf = new SimpleDateFormat(pat);
              String s = sdf.format(new Date(2001-1900, Calendar.JANUARY, 1));
              if (!expected.equals(s)) {
-                 errln("wrong format result: expected="+expected+", got="+s);
+                 fail("wrong format result: expected="+expected+", got="+s);
              }
              Date longday = sdf.parse(s);
              GregorianCalendar cal = new GregorianCalendar();
              cal.setTime(longday);
              if (cal.get(YEAR) != 2001) {
-                 errln("wrong parse result: expected=2001, got=" + cal.get(YEAR));
+                 fail("wrong parse result: expected=2001, got=" + cal.get(YEAR));
              }
          } catch (Exception e) {
              throw e;
          } finally {
              // Restore the initial time zone
              TimeZone.setDefault(initialTimeZone);
          }
      }
  
+     @Test
      public void Test8216969() throws Exception {
          Locale locale = Locale.of("ru");
          String format = "\u0434\u0435\u043a";
          String standalone = "\u0434\u0435\u043a.";
  
< prev index next >