Previous patch to NbBundle introduced regression in getLocalizedValue(Attributes, ...).
Not used in NB product but caught by ModuleManagerTest.
1.1 --- a/openide.util/src/org/openide/util/NbBundle.java Fri Jun 02 18:00:17 2006 +0000
1.2 +++ b/openide.util/src/org/openide/util/NbBundle.java Fri Jun 02 21:38:59 2006 +0000
1.3 @@ -756,7 +756,12 @@
1.4 this.attrs = attrs;
1.5 }
1.6
1.7 - public String get(String k) {
1.8 + public String get(Object _k) {
1.9 + if (!(_k instanceof String)) {
1.10 + return null;
1.11 + }
1.12 + String k = (String) _k;
1.13 +
1.14 Attributes.Name an;
1.15
1.16 try {
2.1 --- a/openide.util/test/unit/src/org/openide/util/NbBundleTest.java Fri Jun 02 18:00:17 2006 +0000
2.2 +++ b/openide.util/test/unit/src/org/openide/util/NbBundleTest.java Fri Jun 02 21:38:59 2006 +0000
2.3 @@ -7,13 +7,17 @@
2.4 * http://www.sun.com/
2.5 *
2.6 * The Original Code is NetBeans. The Initial Developer of the Original
2.7 - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
2.8 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
2.9 * Microsystems, Inc. All Rights Reserved.
2.10 */
2.11
2.12 package org.openide.util;
2.13
2.14 +import java.util.HashMap;
2.15 +import java.util.Locale;
2.16 +import java.util.Map;
2.17 import java.util.ResourceBundle;
2.18 +import java.util.jar.Attributes;
2.19 import junit.framework.TestCase;
2.20
2.21 /**
2.22 @@ -63,4 +67,37 @@
2.23
2.24 }
2.25
2.26 + public static void testGetLocalizedValue() throws Exception {
2.27 + Map<String,String> m = new HashMap<String,String>();
2.28 + m.put("k1", "v1");
2.29 + m.put("k1_ja", "v1_ja");
2.30 + m.put("k1_ja_JP", "v1_ja_JP");
2.31 + m.put("k2", "v2");
2.32 + m.put("k3_ja", "v3_ja");
2.33 + assertEquals("v1", NbBundle.getLocalizedValue(m, "k1", Locale.ENGLISH));
2.34 + assertEquals("v1_ja", NbBundle.getLocalizedValue(m, "k1", Locale.JAPANESE));
2.35 + assertEquals("v1_ja_JP", NbBundle.getLocalizedValue(m, "k1", Locale.JAPAN));
2.36 + assertEquals("v2", NbBundle.getLocalizedValue(m, "k2", Locale.ENGLISH));
2.37 + assertEquals("v2", NbBundle.getLocalizedValue(m, "k2", Locale.JAPANESE));
2.38 + assertEquals("v2", NbBundle.getLocalizedValue(m, "k2", Locale.JAPAN));
2.39 + assertEquals(null, NbBundle.getLocalizedValue(m, "k3", Locale.ENGLISH));
2.40 + assertEquals("v3_ja", NbBundle.getLocalizedValue(m, "k3", Locale.JAPANESE));
2.41 + assertEquals("v3_ja", NbBundle.getLocalizedValue(m, "k3", Locale.JAPAN));
2.42 + Attributes attr = new Attributes();
2.43 + attr.putValue("k1", "v1");
2.44 + attr.putValue("k1_ja", "v1_ja");
2.45 + attr.putValue("k1_ja_JP", "v1_ja_JP");
2.46 + attr.putValue("k2", "v2");
2.47 + attr.putValue("k3_ja", "v3_ja");
2.48 + assertEquals("v1", NbBundle.getLocalizedValue(attr, new Attributes.Name("k1"), Locale.ENGLISH));
2.49 + assertEquals("v1_ja", NbBundle.getLocalizedValue(attr, new Attributes.Name("k1"), Locale.JAPANESE));
2.50 + assertEquals("v1_ja_JP", NbBundle.getLocalizedValue(attr, new Attributes.Name("k1"), Locale.JAPAN));
2.51 + assertEquals("v2", NbBundle.getLocalizedValue(attr, new Attributes.Name("k2"), Locale.ENGLISH));
2.52 + assertEquals("v2", NbBundle.getLocalizedValue(attr, new Attributes.Name("k2"), Locale.JAPANESE));
2.53 + assertEquals("v2", NbBundle.getLocalizedValue(attr, new Attributes.Name("k2"), Locale.JAPAN));
2.54 + assertEquals(null, NbBundle.getLocalizedValue(attr, new Attributes.Name("k3"), Locale.ENGLISH));
2.55 + assertEquals("v3_ja", NbBundle.getLocalizedValue(attr, new Attributes.Name("k3"), Locale.JAPANESE));
2.56 + assertEquals("v3_ja", NbBundle.getLocalizedValue(attr, new Attributes.Name("k3"), Locale.JAPAN));
2.57 + }
2.58 +
2.59 }