< prev index next >
test/jdk/java/time/test/java/time/zone/TestZoneRules.java
Print this page
rev 58174 : 8239836: ZoneRules.of() doesn't check transitionList/standardOffsetTL arguments validity
Reviewed-by: rriggs
@@ -22,10 +22,11 @@
*/
package test.java.time.zone;
import java.time.DayOfWeek;
+import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
@@ -34,21 +35,22 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneOffsetTransitionRule;
import java.time.zone.ZoneRules;
+import java.util.Arrays;
import java.util.Collections;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
/**
* @summary Tests for ZoneRules class.
*
- * @bug 8212970 8236903
+ * @bug 8212970 8236903 8239836
*/
@Test
public class TestZoneRules {
private static final ZoneId DUBLIN = ZoneId.of("Europe/Dublin");
@@ -106,10 +108,19 @@
{TOKYO, LocalDateTime.of(LocalDate.of(1950, 9, 10), ONE_AM), ZoneOffset.ofHours(10), ZoneOffset.ofHours(9)},
{TOKYO, LocalDateTime.of(LocalDate.of(1951, 9, 9), ONE_AM), ZoneOffset.ofHours(10), ZoneOffset.ofHours(9)},
};
}
+ @DataProvider
+ private Object[][] emptyTransitionList() {
+ return new Object[][] {
+ // days, offset, std offset, savings, isDST
+ {7, 1, 2, -1, true},
+ {-7, 1, 1, 0, false},
+ };
+ }
+
/**
* Test ZoneRules whether the savings are positive in time zones that have
* negative savings in the source TZ files.
* @bug 8212970
*/
@@ -169,6 +180,29 @@
Collections.singletonList(transitionRule));
ZoneOffset offsetA = zoneRulesA.getOffset(maxLocalDateTime);
ZoneOffset offsetB = zoneRulesB.getOffset(maxLocalDateTime);
assertEquals(offsetA, offsetB);
}
+
+ /**
+ * Tests whether empty "transitionList" is correctly interpreted.
+ * @bug 8239836
+ */
+ @Test(dataProvider="emptyTransitionList")
+ public void test_EmptyTransitionList(int days, int offset, int stdOffset, int savings, boolean isDST) {
+ LocalDateTime transitionDay = LocalDateTime.of(2020, 1, 1, 2, 0);
+ Instant testDay = transitionDay.plusDays(days).toInstant(ZoneOffset.UTC);
+ ZoneOffsetTransition trans = ZoneOffsetTransition.of(
+ transitionDay,
+ ZoneOffset.ofHours(1),
+ ZoneOffset.ofHours(2));
+ ZoneRules rules = ZoneRules.of(ZoneOffset.ofHours(1), ZoneOffset.ofHours(1),
+ Arrays.asList(trans),
+ Collections.emptyList(), Collections.emptyList());
+
+ assertEquals(rules.getOffset(testDay), ZoneOffset.ofHours(offset));
+ assertEquals(rules.getStandardOffset(testDay), ZoneOffset.ofHours(stdOffset));
+ assertEquals(rules.getDaylightSavings(testDay), Duration.ofHours(savings));
+ assertEquals(rules.isDaylightSavings(testDay), isDST);
+ assertTrue(!rules.isFixedOffset());
+ }
}
< prev index next >