ResourceBundleTest.java revision 2362
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A @bug 4049325 4073127 4083270 4106034 4108126 0N/A @summary test Resource Bundle 0N/A @build TestResource TestResource_de TestResource_fr TestResource_fr_CH 0N/A @build TestResource_it FakeTestResource 0N/A @run main ResourceBundleTest 0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved 0N/A * Portions copyright (c) 2007 Sun Microsystems, Inc. 0N/A * All Rights Reserved. 0N/A * The original version of this source code and documentation 0N/A * is copyrighted and owned by Taligent, Inc., a wholly-owned 0N/A * subsidiary of IBM. These materials are provided under terms 0N/A * of a License Agreement between Taligent and Sun. This technology 0N/A * is protected by multiple US and International patents. 0N/A * This notice and attribution to Taligent may not be removed. 0N/A * Taligent is a registered trademark of Taligent, Inc. 0N/A * Permission to use, copy, modify, and distribute this software 0N/A * and its documentation for NON-COMMERCIAL purposes and without 0N/A * fee is hereby granted provided that this copyright notice 0N/A * for further important copyright and licensing information. 0N/A * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF 0N/A * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 0N/A * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 0N/A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR 0N/A * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 0N/A * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. 0N/A // load up the resource bundle, and make sure we got the right one 0N/A // these resources are defines in ResourceBundle_fr 0N/A errln(
"TestResource_fr returned wrong value for \"Time\": got " +
test1);
0N/A errln(
"TestResource_fr returned wrong value for \"For\": got " +
test1);
0N/A errln(
"TestResource_fr returned the wrong value for one of the elements in \"All\"");
0N/A errln(
"TestResource_fr returned an object of the wrong class for \"Good\"");
0N/A errln(
"TestResource_fr returned the wrong value for \"Good\": got " +
test3);
0N/A // This resource is defined in TestResource and inherited by TestResource_fr 0N/A errln(
"TestResource_fr returned the wrong value for one of the elements in \"All\"");
0N/A // This resource is defined in neither TestResource not TestResource_fr 0N/A errln(
"TestResource_fr returned a value for \"Is\" when it shouldn't: got " +
test3);
0N/A String[]
keys = {
"Now",
"Time",
"For",
"All",
"Good",
"Men",
"Come" };
0N/A // load up the resource and check to make sure we got the right class 0N/A // (we don't define be_BY or be, so we fall back on the root default) 0N/A * Repeat TestListResourceBundle on TestResource_it, which is a ListResourceBundle 0N/A * with NO contents. It should gracefully inherit everything from the root 0N/A // load up the resource and check to make sure we got the right class 0N/A // all of these resources are defined in TestResource; it doesn' inherit from anybody 0N/A errln(
"TestResource returned wrong value for \"Now\": got " +
test1);
0N/A errln(
"TestResource returned wrong value for \"Time\": got " +
test1);
0N/A errln(
"TestResource returned wrong value for \"Come\": got " +
test1);
0N/A errln(
"TestResource returned an object of the wrong class for \"Good\"");
0N/A errln(
"TestResource returned the wrong value for \"Good\": got " +
test3);
0N/A errln(
"TestResource returned the wrong value for one of the elements in \"All\"");
0N/A // this item isn't defined in TestResource 0N/A errln(
"TestResource_en returned a value for \"All\" when it shouldn't: got " +
test3);
0N/A * @ summary Bug 4049325 says ResourceBundle.findBundle() uses a hard-coded '/' as 0N/A * the directory separator when searching for properties files. Interestingly, it 0N/A * still works on my NT installation. I can't tell whether this is a required 0N/A * property of all Java implementations (the magic appears to happen ClassLoader. 0N/A * getResourceAsStream(), which is a native function) or a lucky property of my 0N/A * particular implementation. If this bug regresses, this test may still pass 0N/A * because a lower-level facility translates the / to the platform-specific separator 0N/A errln(
"TestResource_es returned wrong value for \"Now\": got " +
test);
0N/A errln(
"TestResource_es returned wrong value for \"Is\": got " +
test);
0N/A errln(
"TestResource_es returned wrong value for \"The\": got " +
test);
0N/A errln(
"TestResource_es returned wrong value for \"Time\": got " +
test);
0N/A // this resource is defined in TestResource and inherited by TestResource_es 0N/A errln(
"TestResource returned the wrong value for one of the elements in \"All\"");
0N/A // this resource is defined in neither TestResource nor TestResource_es 0N/A errln(
"TestResource_es returned a value for \"All\" when it shouldn't: got " +
test);
0N/A String[]
keys = {
"Now",
"Is",
"The",
"Time",
"Good",
"Men",
"Come" };
0N/A // try to find TestResource_fr_CH. Should get fr_CH as its locale 0N/A errln(
"Actual locale for TestResource_fr_CH should have been fr_CH, got " +
locale);
0N/A // try to find TestResource_fr_BE, which doesn't exist. Should get fr as its locale 0N/A errln(
"Actual locale for TestResource_fr_BE should have been fr, got " +
locale);
0N/A // try to find TestResource_iw_IL, which doesn't exist. Should get root locale 0N/A errln(
"Actual locale for TestResource_iw_IL should have been the root locale, got " 0N/A // ResourceBundle.getBundle should never return an object that isn't an instance 0N/A // of ResourceBundle or one of its subclasses. We have a class called FakeTestResource 0N/A // in this package that isn't a ResourceBundle. If we get that back, we barf. 0N/A // (Actually, at the time I fixed this bug, getResource() would throw a 0N/A // ClassCastException in that case.) 0N/A // There's also a properties file called FakeTestResource; we should get back a 0N/A // PropertyResourceBundle pointing to that file. 0N/A // there's also a properties file called FakeTestResource. getBundle() should 0N/A // find it, and it should have the following contents 0N/A // Ensure that the message produced by the exception thrown 0N/A // by ResourceBundle.getObject contains both the class name and 0N/A errln(
"MissingResourceException error message did not contain class name.");
0N/A errln(
"MissingResourceException error message did not contain resource key name.");
0N/A // The getProperty call is to ensure that this test will work with 0N/A // the JTREG test harness. When running in the harness, the current 0N/A // directory is often set to someplace that isn't on the CLASSPATH, 0N/A // so we can't just create the properties files in the current 0N/A // directory. But the harness uses the "test.classes" property to 0N/A // tell us where the classes directory is.