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);
}
Aggregations