GenericTimeZoneNamesTest.java revision 6231:fda257689786
12116Sjkh/*
22116Sjkh * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42116Sjkh *
52116Sjkh * This code is free software; you can redistribute it and/or modify it
62116Sjkh * under the terms of the GNU General Public License version 2 only, as
72116Sjkh * published by the Free Software Foundation.
82116Sjkh *
92116Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT
102116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118870Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
122116Sjkh * version 2 for more details (a copy is included in the LICENSE file that
132116Sjkh * accompanied this code).
142116Sjkh *
152116Sjkh * You should have received a copy of the GNU General Public License version
162116Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
1750476Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
182116Sjkh *
192116Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202116Sjkh * or visit www.oracle.com if you need additional information or have any
212116Sjkh * questions.
222116Sjkh */
232116Sjkh
242116Sjkhimport java.util.*;
252116Sjkhimport sun.util.locale.provider.TimeZoneNameUtility;
262116Sjkh
272116Sjkhpublic class GenericTimeZoneNamesTest {
282116Sjkh    private static final String[] PT = {
292116Sjkh        "America/Los_Angeles", "US/Pacific", "PST"
302116Sjkh    };
312116Sjkh
322116Sjkh    private static int errors = 0;
332116Sjkh
342116Sjkh    public static void main(String[] args) {
352116Sjkh        for (String tag : args) {
362116Sjkh            Locale locale = Locale.forLanguageTag(tag);
372116Sjkh            for (String tzid : PT) {
382116Sjkh                test(tzid, TimeZone.LONG, locale, "Pacific Time");
392116Sjkh                test(tzid, TimeZone.SHORT, locale, "PT");
402116Sjkh            }
412116Sjkh        }
422116Sjkh
432116Sjkh        if (errors != 0) {
442116Sjkh            throw new RuntimeException("test failed");
452116Sjkh        }
462116Sjkh    }
478870Srgrimes
482116Sjkh    private static void test(String tzid, int style, Locale locale, String expected) {
492116Sjkh        // No public API to get generic time zone names (JDK 8)
502116Sjkh        String got = TimeZoneNameUtility.retrieveGenericDisplayName(tzid, style, locale);
518870Srgrimes        if (!expected.equals(got)) {
522116Sjkh            System.err.printf("test: tzid=%s, locale=%s, style=%d, got=\"%s\", expected=\"%s\"%n",
532116Sjkh                              tzid, locale, style, got, expected);
542116Sjkh            errors++;
552116Sjkh        }
562116Sjkh    }
572116Sjkh}
582116Sjkh