Skip to content

Commit c7aa103

Browse files
author
Justin Lu
committed
8372844: Improve usage of test/jdk/java/text/testlib/TestUtils.java locale methods
Reviewed-by: naoto
1 parent c55287d commit c7aa103

File tree

12 files changed

+133
-178
lines changed

12 files changed

+133
-178
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,29 +27,31 @@
2727
* @summary Make sure that cloned SimpleDateFormat objects work
2828
* independently in multiple threads.
2929
* @library /java/text/testlib
30-
* @run main Bug4407042 10
30+
* @run junit Bug4407042
3131
*/
3232

33+
import org.junit.jupiter.api.Assumptions;
34+
import org.junit.jupiter.api.Test;
35+
3336
import java.io.*;
3437
import java.text.*;
3538
import java.util.*;
3639

37-
// Usage: java Bug4407042 [duration]
3840
public class Bug4407042 {
3941

4042
static final String TIME_STRING = "2000/11/18 00:01:00";
4143
static final long UTC_LONG = 974534460000L;
4244
static SimpleDateFormat masterFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
4345
static boolean runrun = true;
44-
static int duration = 100;
46+
static int duration = 10;
4547

48+
@Test
4649
void test() {
4750
Locale locale = Locale.getDefault();
48-
if (!TestUtils.usesAsciiDigits(locale)
49-
|| !TestUtils.usesGregorianCalendar(locale)) {
50-
System.out.println("Skipping this test because locale is " + locale);
51-
return;
52-
}
51+
Assumptions.assumeTrue(TestUtils.usesAsciiDigits(locale),
52+
locale + " does not use ASCII digits");
53+
Assumptions.assumeTrue(TestUtils.usesGregorianCalendar(locale),
54+
locale + " does not use a Gregorian calendar");
5355

5456
masterFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
5557
DateParseThread d1 = new DateParseThread();
@@ -124,11 +126,4 @@ public void run () {
124126
}
125127
}
126128
}
127-
128-
public static void main (String[] args) {
129-
if (args.length == 1) {
130-
duration = Math.max(10, Integer.parseInt(args[0]));
131-
}
132-
new Bug4407042().test();
133-
}
134129
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,19 +28,22 @@
2828
* the same time zone abbreviation for standard and daylight saving
2929
* time.
3030
* @library /java/text/testlib
31-
* @run main Bug4845901
31+
* @run junit/othervm Bug4845901
3232
*/
3333

34+
import org.junit.jupiter.api.Assumptions;
35+
import org.junit.jupiter.api.Test;
36+
3437
import java.util.*;
3538
import java.text.SimpleDateFormat;
3639

3740
public class Bug4845901 {
38-
public static void main (String args[]) {
41+
42+
@Test
43+
void test() {
3944
Locale locale = Locale.getDefault();
40-
if (!TestUtils.usesGregorianCalendar(locale)) {
41-
System.out.println("Skipping this test because locale is " + locale);
42-
return;
43-
}
45+
Assumptions.assumeTrue(TestUtils.usesGregorianCalendar(locale),
46+
locale + " does not use a Gregorian calendar");
4447

4548
TimeZone savedTZ = TimeZone.getDefault();
4649
TimeZone.setDefault(TimeZone.getTimeZone("Australia/Sydney"));
Lines changed: 54 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,93 +25,73 @@
2525
* @test
2626
* @bug 6530336 6537997 8008577 8174269 8333582
2727
* @library /java/text/testlib
28-
* @run main Bug6530336
28+
* @run junit/othervm Bug6530336
2929
*/
3030

31+
import org.junit.jupiter.api.Assumptions;
32+
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.FieldSource;
35+
3136
import java.text.SimpleDateFormat;
3237
import java.util.Calendar;
3338
import java.util.Date;
3439
import java.util.Locale;
3540
import java.util.TimeZone;
3641

37-
public class Bug6530336 {
38-
39-
public static void main(String[] args) throws Exception {
40-
Locale defaultLocale = Locale.getDefault();
41-
TimeZone defaultTimeZone = TimeZone.getDefault();
42-
43-
boolean err = false;
44-
45-
try {
46-
Locale locales[] = Locale.getAvailableLocales();
47-
TimeZone timezone_LA = TimeZone.getTimeZone("America/Los_Angeles");
48-
TimeZone.setDefault(timezone_LA);
49-
50-
TimeZone timezones[] = {
51-
TimeZone.getTimeZone("America/New_York"),
52-
TimeZone.getTimeZone("America/Denver"),
53-
};
54-
55-
String[] expected = {
56-
"Sun Jul 15 12:00:00 PDT 2007",
57-
"Sun Jul 15 14:00:00 PDT 2007",
58-
};
59-
60-
Date[] dates = new Date[2];
42+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
43+
import static org.junit.jupiter.api.Assertions.assertEquals;
6144

62-
for (int i = 0; i < locales.length; i++) {
63-
Locale locale = locales[i];
64-
if (!TestUtils.usesGregorianCalendar(locale)) {
65-
continue;
66-
}
67-
68-
Locale.setDefault(locale);
69-
70-
for (int j = 0; j < timezones.length; j++) {
71-
Calendar cal = Calendar.getInstance(timezones[j]);
72-
cal.set(2007, 6, 15, 15, 0, 0);
73-
dates[j] = cal.getTime();
74-
}
75-
76-
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
45+
public class Bug6530336 {
7746

78-
for (int j = 0; j < timezones.length; j++) {
79-
sdf.setTimeZone(timezones[j]);
80-
String date = sdf.format(dates[j]);
81-
// CLDR localizes GMT format into for some locales. Ignore those cases
82-
if (date.matches(".*GMT[\\s+-]\\D.*") ||
83-
date.contains("UTC") ||
84-
date.contains("TMG") || // Interlingue
85-
date.contains("\u07dc\u07ed\u07d5\u07d6") || // N’Ko
86-
date.contains("\ua2e7\ua0c5\ua395\ua3e6\ua12e\ua209") || // Sichuan Yi, Nuosu
87-
date.contains("\u06af\u0631\u06cc\u0646\u06cc\u0686")) { // Central Kurdish
88-
continue;
89-
}
90-
sdf.setTimeZone(timezone_LA);
91-
String date_LA = sdf.parse(date).toString();
47+
private static final Locale[] locales = Locale.getAvailableLocales();
48+
private static final TimeZone[] timezones = {
49+
TimeZone.getTimeZone("America/New_York"),
50+
TimeZone.getTimeZone("America/Denver"),
51+
};
52+
private static final TimeZone timezone_LA = TimeZone.getTimeZone("America/Los_Angeles");
53+
private static final String[] expected = {
54+
"Sun Jul 15 12:00:00 PDT 2007",
55+
"Sun Jul 15 14:00:00 PDT 2007",
56+
};
57+
private static final Date[] dates = new Date[2];
58+
59+
@BeforeAll
60+
static void setup() {
61+
TimeZone.setDefault(timezone_LA);
62+
}
9263

93-
if (!expected[j].equals(date_LA)) {
94-
System.err.println("Got wrong Pacific time (" +
95-
date_LA + ") for (" + date + ") in " + locale +
96-
" in " + timezones[j] +
97-
".\nExpected=" + expected[j]);
98-
err = true;
99-
}
100-
}
101-
}
64+
@ParameterizedTest
65+
@FieldSource("locales")
66+
void test(Locale locale) {
67+
Assumptions.assumeTrue(TestUtils.usesGregorianCalendar(locale),
68+
locale + " does not use a Gregorian calendar");
69+
Locale.setDefault(locale);
70+
71+
for (int j = 0; j < timezones.length; j++) {
72+
Calendar cal = Calendar.getInstance(timezones[j]);
73+
cal.set(2007, 6, 15, 15, 0, 0);
74+
dates[j] = cal.getTime();
10275
}
103-
catch (Exception e) {
104-
e.printStackTrace();
105-
err = true;
106-
}
107-
finally {
108-
Locale.setDefault(defaultLocale);
109-
TimeZone.setDefault(defaultTimeZone);
11076

111-
if (err) {
112-
throw new RuntimeException("Failed.");
77+
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
78+
79+
for (int j = 0; j < timezones.length; j++) {
80+
sdf.setTimeZone(timezones[j]);
81+
String date = sdf.format(dates[j]);
82+
// CLDR localizes GMT format into for some locales. Ignore those cases
83+
if (date.matches(".*GMT[\\s+-]\\D.*") ||
84+
date.contains("UTC") ||
85+
date.contains("TMG") || // Interlingue
86+
date.contains("ߜ߭ߕߖ") || // N’Ko
87+
date.contains("ꋧꃅꎕꏦꄮꈉ") || // Sichuan Yi, Nuosu
88+
date.contains("گرینیچ")) { // Central Kurdish
89+
continue;
11390
}
91+
sdf.setTimeZone(timezone_LA);
92+
String date_LA = assertDoesNotThrow(() -> sdf.parse(date).toString());
93+
assertEquals(expected[j], date_LA,
94+
"Got wrong Pacific time (%s) for (%s) in %s in %s.".formatted(date_LA, date, locale, timezones[j]));
11495
}
11596
}
116-
11797
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.*;
2626
import java.io.*;
2727

28+
import org.junit.jupiter.api.Assumptions;
2829
import org.junit.jupiter.api.Test;
2930

3031
import static org.junit.jupiter.api.Assertions.fail;
@@ -170,10 +171,8 @@ public void Test4056591() {
170171
@Test
171172
public void Test4059917() {
172173
Locale locale = Locale.getDefault();
173-
if (!TestUtils.usesAsciiDigits(locale)) {
174-
System.out.println("Skipping this test because locale is " + locale);
175-
return;
176-
}
174+
Assumptions.assumeTrue(TestUtils.usesAsciiDigits(locale),
175+
locale + " does not use ASCII digits");
177176

178177
SimpleDateFormat fmt;
179178
String myDate;

test/jdk/java/text/Format/MessageFormat/MessageRegression.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,6 +53,7 @@
5353
import java.io.ObjectInputStream;
5454
import java.io.Serializable;
5555

56+
import org.junit.jupiter.api.Assumptions;
5657
import org.junit.jupiter.api.Test;
5758

5859
import static org.junit.jupiter.api.Assertions.fail;
@@ -126,10 +127,8 @@ public void Test4058973() {
126127
@Test
127128
public void Test4031438() {
128129
Locale locale = Locale.getDefault();
129-
if (!TestUtils.usesAsciiDigits(locale)) {
130-
System.out.println("Skipping this test because locale is " + locale);
131-
return;
132-
}
130+
Assumptions.assumeTrue(TestUtils.usesAsciiDigits(locale),
131+
locale + " does not use ASCII digits");
133132

134133
String pattern1 = "Impossible {1} has occurred -- status code is {0} and message is {2}.";
135134
String pattern2 = "Double '' Quotes {0} test and quoted '{1}' test plus 'other {2} stuff'.";

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.io.*;
5959
import java.math.BigInteger;
6060

61+
import org.junit.jupiter.api.Assumptions;
6162
import sun.util.resources.LocaleData;
6263

6364
import org.junit.jupiter.api.Test;
@@ -109,10 +110,8 @@ public void Test4074620() {
109110
@Test
110111
public void Test4088161 (){
111112
Locale locale = Locale.getDefault();
112-
if (!TestUtils.usesAsciiDigits(locale)) {
113-
System.out.println("Skipping this test because locale is " + locale);
114-
return;
115-
}
113+
Assumptions.assumeTrue(TestUtils.usesAsciiDigits(locale),
114+
locale + " does not use ASCII digits");
116115

117116
DecimalFormat df = new DecimalFormat();
118117
double d = 100;

test/jdk/java/util/Calendar/CalendarLimitTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
import java.util.*;
3333
import java.text.*;
3434

35+
import org.junit.jupiter.api.Assumptions;
3536
import org.junit.jupiter.api.Test;
3637

3738
import static org.junit.jupiter.api.Assertions.fail;
@@ -130,10 +131,8 @@ int test(long millis, Calendar cal, DateFormat fmt)
130131
public void TestCalendarLimit()
131132
{
132133
Locale locale = Locale.getDefault();
133-
if (!TestUtils.usesGregorianCalendar(locale)) {
134-
System.out.println("Skipping this test because locale is " + locale);
135-
return;
136-
}
134+
Assumptions.assumeTrue(TestUtils.usesGregorianCalendar(locale),
135+
locale + " does not use a Gregorian calendar");
137136
ORIGIN = julianDayToMillis(JAN_1_1_JULIAN_DAY);
138137

139138
Calendar cal = Calendar.getInstance();

0 commit comments

Comments
 (0)