8012638: test/java/time/test/java/util/TestFormatter fails in UTC TZ

Updated the offending test case

Reviewed-by: alanb
This commit is contained in:
Xueming Shen 2013-04-24 21:27:52 +00:00
parent 3db24cefee
commit 0872993c6c

View File

@ -25,6 +25,7 @@ package test.java.util;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.util.*;
@ -34,6 +35,7 @@ import static org.testng.Assert.assertEquals;
/* @test
* @summary Unit test for j.u.Formatter threeten date/time support
* @bug 8003680 8012638
*/
@Test
public class TestFormatter {
@ -64,16 +66,23 @@ public class TestFormatter {
//locales = Locale.getAvailableLocales();
Locale[] locales = new Locale[] {
Locale.ENGLISH, Locale.FRENCH, Locale.JAPANESE, Locale.CHINESE};
Random r = new Random();
ZonedDateTime zdt = ZonedDateTime.now();
ZonedDateTime zdt0 = ZonedDateTime.now();
ZonedDateTime[] zdts = new ZonedDateTime[] {
zdt0,
zdt0.withZoneSameLocal(ZoneId.of("UTC")),
zdt0.withZoneSameLocal(ZoneId.of("GMT")),
zdt0.withZoneSameLocal(ZoneId.of("UT")),
};
while (N-- > 0) {
for (ZonedDateTime zdt : zdts) {
zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
.with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
Instant instant = zdt.toInstant();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(instant.toEpochMilli());
cal.setTimeZone(TimeZone.getTimeZone(zdt.getZone()));
for (Locale locale : locales) {
for (String fmtStr : fmtStrDate) {
testDate(fmtStr, locale, zdt, cal);
@ -85,6 +94,7 @@ public class TestFormatter {
testInstant(locale, instant, zdt, cal);
}
}
}
if (verbose) {
if (failure != 0) {
System.out.println("Total " + failure + "/" + total + " tests failed");
@ -146,6 +156,10 @@ public class TestFormatter {
}
private String toZoneIdStr(String expected) {
return expected.replaceAll("(?:GMT|UTC)(?<off>[+\\-]?[0-9]{2}:[0-9]{2})", "${off}");
}
private String toZoneOffsetStr(String expected) {
return expected.replaceAll("(?:GMT|UTC)(?<off>[+\\-]?[0-9]{2}:[0-9]{2})", "${off}")
.replaceAll("GMT|UTC|UT", "Z");
}
@ -159,7 +173,7 @@ public class TestFormatter {
Calendar cal0 = Calendar.getInstance();
cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
expected = toZoneIdStr(test(fmtStr, locale, null, cal0));
expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
test(fmtStr, locale, expected, zdt.toOffsetDateTime());
test(fmtStr, locale, expected, zdt.toOffsetDateTime().toOffsetTime());