J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | /* |
| 24 | * @test |
| 25 | * @bug 6190861 |
| 26 | * @summary Make sure to always load the default locale's bundle when |
| 27 | * there's no bundle for the requested locale. |
| 28 | */ |
| 29 | |
| 30 | import java.util.*; |
| 31 | |
| 32 | public class Bug6190861 { |
| 33 | |
| 34 | static public void main(String[] args) { |
| 35 | Locale.setDefault(new Locale("en", "US")); |
| 36 | |
| 37 | List localeList = new ArrayList(); |
| 38 | localeList.add(Locale.ENGLISH); |
| 39 | localeList.add(Locale.KOREA); |
| 40 | localeList.add(Locale.UK); |
| 41 | localeList.add(new Locale("en", "CA")); |
| 42 | localeList.add(Locale.ENGLISH); |
| 43 | |
| 44 | Iterator iter = localeList.iterator(); |
| 45 | while (iter.hasNext()){ |
| 46 | Locale currentLocale = (Locale) iter.next(); |
| 47 | System.out.println("\ncurrentLocale = " |
| 48 | + currentLocale.getDisplayName()); |
| 49 | |
| 50 | ResourceBundle messages = ResourceBundle.getBundle("Bug6190861Data",currentLocale); |
| 51 | |
| 52 | Locale messagesLocale = messages.getLocale(); |
| 53 | System.out.println("messagesLocale = " |
| 54 | + messagesLocale.getDisplayName()); |
| 55 | checkMessages(messages); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | static void checkMessages(ResourceBundle messages) { |
| 60 | String greetings = messages.getString("greetings"); |
| 61 | String inquiry = messages.getString("inquiry"); |
| 62 | String farewell = messages.getString("farewell"); |
| 63 | System.out.println(greetings); |
| 64 | System.out.println(inquiry); |
| 65 | System.out.println(farewell); |
| 66 | if (!greetings.equals("Hiya.")) { |
| 67 | throw new RuntimeException("got wrong resource bundle"); |
| 68 | } |
| 69 | } |
| 70 | } |