OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / api / java / util / ListResourceBundleTest.java
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
18 package tests.api.java.util;
19
20 import dalvik.annotation.TestTargetNew;
21 import dalvik.annotation.TestTargets;
22 import dalvik.annotation.TestLevel;
23 import dalvik.annotation.TestTargetClass;
24
25 import java.util.Enumeration;
26 import java.util.ListResourceBundle;
27 import java.util.Locale;
28 import java.util.ResourceBundle;
29 import java.util.Vector;
30
31 @TestTargetClass(java.util.ListResourceBundle.class)
32 public class ListResourceBundleTest extends junit.framework.TestCase {
33
34     /**
35      * @tests java.util.ListResourceBundle#getKeys()
36      */
37     @TestTargets({
38         @TestTargetNew(
39             level = TestLevel.COMPLETE,
40             notes = "",
41             method = "getKeys",
42             args = {}
43         ),
44         @TestTargetNew(
45             level = TestLevel.COMPLETE,
46             notes = "",
47             method = "ListResourceBundle",
48             args = {}
49         ),
50         @TestTargetNew(
51             level = TestLevel.COMPLETE,
52             notes = "",
53             method = "getContents",
54             args = {}
55         )
56     })
57     public void test_getKeys() {
58         ResourceBundle bundle;
59         String name = "tests.support.Support_TestResource";
60         Locale.setDefault(new Locale("en", "US"));
61         bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
62         Enumeration keys = bundle.getKeys();
63         Vector result = new Vector();
64         while (keys.hasMoreElements()) {
65             result.addElement(keys.nextElement());
66         }
67         assertTrue("Missing key parent1", result.contains("parent1"));
68         assertTrue("Missing key parent2", result.contains("parent2"));
69         assertTrue("Missing key parent3", result.contains("parent3"));
70         assertTrue("Missing key parent4", result.contains("parent4"));
71         assertTrue("Missing key child1", result.contains("child1"));
72         assertTrue("Missing key child2", result.contains("child2"));
73         assertTrue("Missing key child3", result.contains("child3"));
74     }
75
76
77     @TestTargets({
78         @TestTargetNew(
79             level = TestLevel.COMPLETE,
80             notes = "",
81             method = "handleGetObject",
82             args = {java.lang.String.class}
83         ),
84         @TestTargetNew(
85             level = TestLevel.COMPLETE,
86             notes = "",
87             method = "ListResourceBundle",
88             args = {}
89         ),
90         @TestTargetNew(
91             level = TestLevel.COMPLETE,
92             notes = "",
93             method = "getContents",
94             args = {}
95         )
96     })
97     public void test_handleGetObjectLjava_lang_String() {
98         ListResourceBundle bundle;
99         String name = "tests.support.Support_TestResource";
100         Locale.setDefault(new Locale("en", "US"));
101         bundle = (ListResourceBundle)ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
102         Enumeration keys = bundle.getKeys();
103         String keyValue = null;
104         Vector result = new Vector();
105         while (keys.hasMoreElements()) {
106             result.addElement(bundle.handleGetObject((String)keys.nextElement()));
107         }
108         assertEquals(9, result.size());
109         assertTrue(result.contains(null));
110         assertTrue(result.contains("frFRVARValue4"));
111         assertTrue(result.contains("frFRVARChildValue1"));
112         assertTrue(result.contains("frFRVARChildValue2"));
113         assertTrue(result.contains("frFRVARChildValue3"));
114         assertTrue(result.remove(null));
115         assertTrue(result.remove(null));
116         assertTrue(result.remove(null));
117     }
118
119     protected void setUp() {
120     }
121
122     protected void tearDown() {
123     }
124 }