public void TestSimpleTimeZoneCoverage() {
long time1 = getUTCMillis(1990, Calendar.JUNE, 1);
long time2 = getUTCMillis(2000, Calendar.JUNE, 1);
TimeZoneTransition tzt1, tzt2;
// BasicTimeZone API implementation in SimpleTimeZone
SimpleTimeZone stz1 = new SimpleTimeZone(-5*HOUR, "GMT-5");
tzt1 = stz1.getNextTransition(time1, false);
if (tzt1 != null) {
errln("FAIL: No transition must be returned by getNextTranstion for SimpleTimeZone with no DST rule");
}
tzt1 = stz1.getPreviousTransition(time1, false);
if (tzt1 != null) {
errln("FAIL: No transition must be returned by getPreviousTransition for SimpleTimeZone with no DST rule");
}
TimeZoneRule[] tzrules = stz1.getTimeZoneRules();
if (tzrules.length != 1 || !(tzrules[0] instanceof InitialTimeZoneRule)) {
errln("FAIL: Invalid results returned by SimpleTimeZone#getTimeZoneRules");
}
// Set DST rule
stz1.setStartRule(Calendar.MARCH, 11, 2*HOUR); // March 11
stz1.setEndRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2*HOUR); // First Sunday in November
tzt1 = stz1.getNextTransition(time1, false);
if (tzt1 == null) {
errln("FAIL: Non-null transition must be returned by getNextTranstion for SimpleTimeZone with a DST rule");
} else {
String str = tzt1.toString();
if (str == null || str.length() == 0) {
errln("FAIL: TimeZoneTransition#toString returns null or empty string");
} else {
logln(str);
}
}
tzt1 = stz1.getPreviousTransition(time1, false);
if (tzt1 == null) {
errln("FAIL: Non-null transition must be returned by getPreviousTransition for SimpleTimeZone with a DST rule");
}
tzrules = stz1.getTimeZoneRules();
if (tzrules.length != 3 || !(tzrules[0] instanceof InitialTimeZoneRule)
|| !(tzrules[1] instanceof AnnualTimeZoneRule)
|| !(tzrules[2] instanceof AnnualTimeZoneRule)) {
errln("FAIL: Invalid results returned by SimpleTimeZone#getTimeZoneRules for a SimpleTimeZone with DST");
}
// Set DST start year
stz1.setStartYear(2007);
tzt1 = stz1.getPreviousTransition(time1, false);
if (tzt1 != null) {
errln("FAIL: No transition must be returned before 1990");
}
tzt1 = stz1.getNextTransition(time1, false); // transition after 1990-06-01
tzt2 = stz1.getNextTransition(time2, false); // transition after 2000-06-01
if (tzt1 == null || tzt2 == null || !tzt1.equals(tzt2)) {
errln("FAIL: Bad transition returned by SimpleTimeZone#getNextTransition");
}
}