@Test public void testMaxTimeZoneKey() { boolean foundMax = false; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertTrue(timeZoneKey.getKey() <= MAX_TIME_ZONE_KEY, timeZoneKey + " key is larger than max key " + MAX_TIME_ZONE_KEY); foundMax = foundMax || (timeZoneKey.getKey() == MAX_TIME_ZONE_KEY); } assertTrue(foundMax, "Did not find a time zone with the MAX_TIME_ZONE_KEY"); }
@Test public void testZoneKeyIdRange() { boolean[] hasValue = new boolean[MAX_TIME_ZONE_KEY + 1]; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { short key = timeZoneKey.getKey(); assertTrue(key >= 0, timeZoneKey + " has a negative time zone key"); assertFalse(hasValue[key], "Another time zone has the same zone key as " + timeZoneKey); hasValue[key] = true; } // previous spot for Canada/East-Saskatchewan assertFalse(hasValue[2040]); hasValue[2040] = true; // previous spot for EST assertFalse(hasValue[2180]); hasValue[2180] = true; // previous spot for HST assertFalse(hasValue[2186]); hasValue[2186] = true; // previous spot for MST assertFalse(hasValue[2196]); hasValue[2196] = true; for (int i = 0; i < hasValue.length; i++) { assertTrue(hasValue[i], "There is no time zone with key " + i); } }
@Test public void testZoneKeyData() { Hasher hasher = Hashing.murmur3_128().newHasher(); SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() { @Override public int compare(TimeZoneKey left, TimeZoneKey right) { return Short.compare(left.getKey(), right.getKey()); } }, TimeZoneKey.getTimeZoneKeys()); for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) { hasher.putShort(timeZoneKey.getKey()); hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8); } // Zone file should not (normally) be changed, so let's make this more difficult assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!"); }
@Test public void testZoneKeyLookup() { for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getKey()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toUpperCase(ENGLISH)), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toLowerCase(ENGLISH)), timeZoneKey); } }