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 tests.api.java.util;
19
20import dalvik.annotation.TestTargetNew;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetClass;
24
25import java.util.Enumeration;
26import java.util.MissingResourceException;
27import java.util.PropertyResourceBundle;
28import java.util.Vector;
29
30@TestTargetClass(PropertyResourceBundle.class)
31public class PropertyResourceBundleTest extends junit.framework.TestCase {
32
33    static PropertyResourceBundle prb;
34
35    /**
36     * @tests java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream)
37     */
38    @TestTargetNew(
39        level = TestLevel.COMPLETE,
40        notes = "",
41        method = "PropertyResourceBundle",
42        args = {java.io.InputStream.class}
43    )
44    public void test_ConstructorLjava_io_InputStream() {
45        // Test for method java.util.PropertyResourceBundle(java.io.InputStream)
46        assertTrue("Used to test", true);
47    }
48
49    /**
50     * @tests java.util.PropertyResourceBundle#getKeys()
51     */
52    @TestTargetNew(
53        level = TestLevel.COMPLETE,
54        notes = "",
55        method = "getKeys",
56        args = {}
57    )
58    public void test_getKeys() {
59        Enumeration keyEnum = prb.getKeys();
60        Vector test = new Vector();
61        int keyCount = 0;
62        while (keyEnum.hasMoreElements()) {
63            test.addElement(keyEnum.nextElement());
64            keyCount++;
65        }
66
67        assertEquals("Returned the wrong number of keys", 2, keyCount);
68        assertTrue("Returned the wrong keys", test.contains("p1")
69                && test.contains("p2"));
70    }
71
72    /**
73     * @tests java.util.PropertyResourceBundle#handleGetObject(java.lang.String)
74     */
75    @TestTargetNew(
76        level = TestLevel.COMPLETE,
77        notes = "",
78        method = "handleGetObject",
79        args = {java.lang.String.class}
80    )
81    public void test_handleGetObjectLjava_lang_String() {
82        // Test for method java.lang.Object
83        // java.util.PropertyResourceBundle.handleGetObject(java.lang.String)
84        try {
85            assertTrue("Returned incorrect objects", prb.getObject("p1")
86                    .equals("one")
87                    && prb.getObject("p2").equals("two"));
88        } catch (MissingResourceException e) {
89            fail(
90                    "Threw MisingResourceException for a key contained in the bundle");
91        }
92        try {
93            prb.getObject("Not in the bundle");
94        } catch (MissingResourceException e) {
95            return;
96        }
97        fail(
98                "Failed to throw MissingResourceException for object not in the bundle");
99    }
100
101    /**
102     * Sets up the fixture, for example, open a network connection. This method
103     * is called before a test is executed.
104     */
105    protected void setUp() {
106        java.io.InputStream propertiesStream = new java.io.ByteArrayInputStream(
107                "p1=one\np2=two".getBytes());
108        try {
109            prb = new PropertyResourceBundle(propertiesStream);
110        } catch (java.io.IOException e) {
111            fail(
112                    "Contruction of PropertyResourceBundle threw IOException");
113        }
114    }
115
116    /**
117     * Tears down the fixture, for example, close a network connection. This
118     * method is called after a test is executed.
119     */
120    protected void tearDown() {
121    }
122}
123