Added tests for uncovered TimeZoneNames methods.
Bug: 22023363
(cherry picked from commit 5da052dc8093823a90dfcd37d5de3b57a492a72f)
Change-Id: If3826be3a4b5d9a76cb8792c4695ad4bf6e9becb
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 5af46b9..577633b 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.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 @@
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);
+ }
+ }
+ }
}