diff options
author | Paul Duffin <paulduffin@google.com> | 2016-03-22 15:50:41 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2016-03-23 13:28:32 +0000 |
commit | 5da052dc8093823a90dfcd37d5de3b57a492a72f (patch) | |
tree | 0948b537d52a56c83efe349baf4c76b3a0a50cd7 /android_icu4j/cts-coverage/src/main/tests/android/icu/cts | |
parent | f0380026d1a7ecc937edca362561a6b6f9d2de4e (diff) | |
download | icu-5da052dc8093823a90dfcd37d5de3b57a492a72f.tar.gz |
Added tests for uncovered TimeZoneNames methods.
Bug: 22023363
Change-Id: I327ae2447dd036bf0ac82240754d8d351efac01a
Diffstat (limited to 'android_icu4j/cts-coverage/src/main/tests/android/icu/cts')
-rw-r--r-- | android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java index 5af46b94f..577633b5a 100644 --- a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java +++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java @@ -16,7 +16,9 @@ package android.icu.cts.coverage.text; import android.icu.text.TimeZoneNames; +import android.icu.util.TimeZone; import android.icu.util.ULocale; +import java.util.Collections; import java.util.Locale; import java.util.Set; import org.junit.Test; @@ -24,9 +26,14 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Extra tests to improve CTS Test Coverage. + * + * Where necessary (i.e. when a method is abstract) it tests the implementations of TimeZoneNames; + * excluding the default one which shouldn't be used on Android. */ @RunWith(JUnit4.class) public class TimeZoneNamesTest { @@ -48,4 +55,81 @@ public class TimeZoneNamesTest { assertEquals("Id: " + availableId, uLocaleName, localeName); } } + + @Test + public void testGetAvailableMetaZoneIDs() { + TimeZoneNames japaneseNames = TimeZoneNames.getInstance(ULocale.JAPANESE); + Set<String> allJapan = japaneseNames.getAvailableMetaZoneIDs(); + + TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE); + Set<String> tzdbAll = tzdbNames.getAvailableMetaZoneIDs(); + + // The data is the same in the current implementation. + assertEquals(allJapan, tzdbAll); + + // Make sure that there is something. + assertTrue("count of zone ids is less than 100", allJapan.size() >= 180); + } + + @Test + public void testGetAvailableMetaZoneIDs_String() { + TimeZoneNames japaneseNames = TimeZoneNames.getInstance(ULocale.JAPANESE); + assertEquals(Collections.singleton("America_Pacific"), + japaneseNames.getAvailableMetaZoneIDs("America/Los_Angeles")); + + TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE); + assertEquals(Collections.singleton("Taipei"), + tzdbNames.getAvailableMetaZoneIDs("Asia/Taipei")); + } + + @Test + public void testGetMetaZoneDisplayName() { + TimeZoneNames usNames = TimeZoneNames.getInstance(ULocale.US); + + String europeanCentralName = usNames.getMetaZoneDisplayName("Europe_Central", + TimeZoneNames.NameType.LONG_STANDARD); + assertEquals("Central European Standard Time", europeanCentralName); + + TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.CHINESE); + String americaPacificName = tzdbNames.getMetaZoneDisplayName("America_Pacific", + TimeZoneNames.NameType.SHORT_DAYLIGHT); + assertEquals("PDT", americaPacificName); + } + + @Test + public void testGetMetaZoneID() { + TimeZoneNames usNames = TimeZoneNames.getInstance(ULocale.US); + + String europeanCentralName = usNames.getMetaZoneID("Europe/Paris", 0); + assertEquals("Europe_Central", europeanCentralName); + + TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.KOREAN); + String seoulName = tzdbNames.getMetaZoneID("Asia/Seoul", 0); + assertEquals("Korea", seoulName); + + // Now try Jan 1st 1945 GMT + seoulName = tzdbNames.getMetaZoneID("Asia/Seoul", -786240000000L); + assertNull(seoulName); + } + + @Test + public void testGetTimeZoneDisplayName() { + TimeZoneNames frenchNames = TimeZoneNames.getInstance(ULocale.FRENCH); + String dublinName = frenchNames.getTimeZoneDisplayName("Europe/Dublin", + TimeZoneNames.NameType.LONG_DAYLIGHT); + assertEquals("heure d’été irlandaise", dublinName); + + String dublinLocation = frenchNames.getTimeZoneDisplayName("Europe/Dublin", + TimeZoneNames.NameType.EXEMPLAR_LOCATION); + assertEquals("Dublin", dublinLocation); + + // All the names returned by this are null. + TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(ULocale.KOREAN); + for (String tzId : TimeZone.getAvailableIDs()) { + for (TimeZoneNames.NameType nameType : TimeZoneNames.NameType.values()) { + String name = tzdbNames.getTimeZoneDisplayName(tzId, nameType); + assertNull("TZ:" + tzId + ", NameType: " + nameType + ", value: " + name, name); + } + } + } } |