1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.tests.java.util;
19
20import java.util.Enumeration;
21import java.util.ListResourceBundle;
22import java.util.Locale;
23import java.util.ResourceBundle;
24import java.util.Vector;
25
26public class ListResourceBundleTest extends junit.framework.TestCase {
27    /**
28     * java.util.ListResourceBundle#getKeys()
29     */
30    public void test_getKeys() {
31        ResourceBundle bundle;
32        String name = "tests.support.Support_TestResource";
33        Locale.setDefault(new Locale("en", "US"));
34        bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
35        Enumeration<String> keys = bundle.getKeys();
36        Vector<String> result = new Vector<String>();
37        while (keys.hasMoreElements()) {
38            result.addElement(keys.nextElement());
39        }
40        assertTrue("Missing key parent1", result.contains("parent1"));
41        assertTrue("Missing key parent2", result.contains("parent2"));
42        assertTrue("Missing key parent3", result.contains("parent3"));
43        assertTrue("Missing key parent4", result.contains("parent4"));
44        assertTrue("Missing key child1", result.contains("child1"));
45        assertTrue("Missing key child2", result.contains("child2"));
46        assertTrue("Missing key child3", result.contains("child3"));
47    }
48
49    public void test_handleGetObjectLjava_lang_String() {
50        ListResourceBundle bundle;
51        String name = "tests.support.Support_TestResource";
52        Locale.setDefault(new Locale("en", "US"));
53        bundle = (ListResourceBundle) ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
54        Enumeration keys = bundle.getKeys();
55        String keyValue = null;
56        Vector result = new Vector();
57        while (keys.hasMoreElements()) {
58            result.addElement(bundle.handleGetObject((String)keys.nextElement()));
59        }
60        assertEquals(9, result.size());
61        assertTrue(result.contains(null));
62        assertTrue(result.contains("frFRVARValue4"));
63        assertTrue(result.contains("frFRVARChildValue1"));
64        assertTrue(result.contains("frFRVARChildValue2"));
65        assertTrue(result.contains("frFRVARChildValue3"));
66        assertTrue(result.remove(null));
67        assertTrue(result.remove(null));
68        assertTrue(result.remove(null));
69    }
70
71    protected void setUp() {
72    }
73
74    protected void tearDown() {
75    }
76}
77