3089N/A/*
3089N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3089N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3089N/A *
3089N/A * This code is free software; you can redistribute it and/or modify it
3089N/A * under the terms of the GNU General Public License version 2 only, as
3089N/A * published by the Free Software Foundation.
3089N/A *
3089N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3089N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3089N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3089N/A * version 2 for more details (a copy is included in the LICENSE file that
3089N/A * accompanied this code).
3089N/A *
3089N/A * You should have received a copy of the GNU General Public License version
3089N/A * 2 along with this work; if not, write to the Free Software Foundation,
3089N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3089N/A *
3089N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3089N/A * or visit www.oracle.com if you need additional information or have any
3089N/A * questions.
3089N/A */
3089N/A/*
3089N/A * @test
3089N/A * @bug 6807534
3089N/A * @summary check whether the default implementation of
3089N/A * CurrencNameProvider.getDisplayName(String, Locale) throws appropriate
3089N/A * exceptions when necessary.
3089N/A */
3089N/A
3089N/Aimport java.util.Locale;
3089N/Aimport java.util.spi.CurrencyNameProvider;
3089N/A
3089N/Apublic class Bug6807534 {
3089N/A
3089N/A static final CurrencyNameProvider cnp = new CurrencyNameProviderImpl();
3089N/A
3089N/A public static void main(String[] args) throws Exception {
3089N/A // test for NullPointerException (currencyCode)
3089N/A try {
3089N/A cnp.getDisplayName(null, Locale.US);
3089N/A throwException("NPE was not thrown with null currencyCode");
3089N/A } catch (NullPointerException npe) {}
3089N/A
3089N/A // test for NullPointerException (locale)
3089N/A try {
3089N/A cnp.getDisplayName("USD", null);
3089N/A throwException("NPE was not thrown with null locale");
3089N/A } catch (NullPointerException npe) {}
3089N/A
3089N/A // test for IllegalArgumentException (illegal currencyCode)
3089N/A try {
3089N/A cnp.getDisplayName("INVALID", Locale.US);
3089N/A throwException("IllegalArgumentException was not thrown with invalid currency code");
3089N/A } catch (IllegalArgumentException iae) {}
3089N/A try {
3089N/A cnp.getDisplayName("inv", Locale.US);
3089N/A throwException("IllegalArgumentException was not thrown with invalid currency code");
3089N/A } catch (IllegalArgumentException iae) {}
3089N/A
3089N/A // test for IllegalArgumentException (non-supported locale)
3089N/A try {
3089N/A cnp.getDisplayName("USD", Locale.JAPAN);
3089N/A throwException("IllegalArgumentException was not thrown with non-supported locale");
3089N/A } catch (IllegalArgumentException iae) {}
3089N/A }
3089N/A
3089N/A static void throwException(String msg) {
3089N/A throw new RuntimeException("test failed. "+msg);
3089N/A }
3089N/A
3089N/A static class CurrencyNameProviderImpl extends CurrencyNameProvider {
3089N/A // dummy implementation
3089N/A public String getSymbol(String currencyCode, Locale locale) {
3089N/A return "";
3089N/A }
3089N/A
3089N/A public Locale[] getAvailableLocales() {
3089N/A Locale[] avail = new Locale[1];
3089N/A avail[0] = Locale.US;
3089N/A return avail;
3089N/A }
3089N/A }
3089N/A}