Search in sources :

Example 16 with TimeZoneNames

use of android.icu.text.TimeZoneNames in project j2objc by google.

the class TimeZoneFormatTest method TestGetDisplayNames.

@Test
public void TestGetDisplayNames() {
    long date = System.currentTimeMillis();
    NameType[] types = new NameType[] { NameType.LONG_STANDARD, NameType.LONG_DAYLIGHT, NameType.SHORT_STANDARD, NameType.SHORT_DAYLIGHT };
    Set<String> zones = ZoneMeta.getAvailableIDs(SystemTimeZoneType.ANY, null, null);
    int casesTested = 0;
    Random rnd = new Random(2016);
    for (ULocale uloc : ULocale.getAvailableLocales()) {
        if (rnd.nextDouble() > 0.01) {
            continue;
        }
        for (String zone : zones) {
            if (rnd.nextDouble() > 0.01) {
                continue;
            }
            casesTested++;
            // Test default TimeZoneNames (uses an overridden getDisplayNames)
            {
                TimeZoneNames tznames = TimeZoneNames.getInstance(uloc);
                tznames.loadAllDisplayNames();
                String[] result = new String[types.length];
                tznames.getDisplayNames(zone, types, date, result, 0);
                for (int i = 0; i < types.length; i++) {
                    NameType type = types[i];
                    String expected = result[i];
                    String actual = tznames.getDisplayName(zone, type, date);
                    assertEquals("TimeZoneNames: getDisplayNames() returns different result than getDisplayName()" + " for " + zone + " in locale " + uloc, expected, actual);
                }
                // Coverage for empty call to getDisplayNames
                tznames.getDisplayNames(null, null, 0, null, 0);
            }
            // Test TZDBTimeZoneNames (uses getDisplayNames from abstract class)
            {
                TimeZoneNames tznames = new TZDBTimeZoneNames(uloc);
                tznames.loadAllDisplayNames();
                String[] result = new String[types.length];
                tznames.getDisplayNames(zone, types, date, result, 0);
                for (int i = 0; i < types.length; i++) {
                    NameType type = types[i];
                    String expected = result[i];
                    String actual = tznames.getDisplayName(zone, type, date);
                    assertEquals("TZDBTimeZoneNames: getDisplayNames() returns different result than getDisplayName()" + " for " + zone + " in locale " + uloc, expected, actual);
                }
                // Coverage for empty call to getDisplayNames
                tznames.getDisplayNames(null, null, 0, null, 0);
            }
        }
    }
    assertTrue("No cases were tested", casesTested > 0);
}
Also used : ULocale(android.icu.util.ULocale) Random(java.util.Random) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) TimeZoneNames(android.icu.text.TimeZoneNames) NameType(android.icu.text.TimeZoneNames.NameType) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) Test(org.junit.Test)

Aggregations

TimeZoneNames (android.icu.text.TimeZoneNames)16 Locale (java.util.Locale)10 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 TimeZone (java.util.TimeZone)5 TZDBTimeZoneNames (android.icu.impl.TZDBTimeZoneNames)4 ULocale (android.icu.util.ULocale)4 Test (org.junit.Test)4 TimeZoneFormat (android.icu.text.TimeZoneFormat)3 TimeType (android.icu.text.TimeZoneFormat.TimeType)2 NameType (android.icu.text.TimeZoneNames.NameType)2 Factory (android.icu.text.TimeZoneNames.Factory)1 BasicTimeZone (android.icu.util.BasicTimeZone)1 Output (android.icu.util.Output)1 SimpleTimeZone (android.icu.util.SimpleTimeZone)1 TimeZone (android.icu.util.TimeZone)1 ParseException (java.text.ParseException)1