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