01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 org.apache.harmony.luni.tests.java.util;
19:
20: import java.util.Enumeration;
21: import java.util.MissingResourceException;
22: import java.util.PropertyResourceBundle;
23: import java.util.Vector;
24:
25: public class PropertyResourceBundleTest extends
26: junit.framework.TestCase {
27:
28: static PropertyResourceBundle prb;
29:
30: /**
31: * @tests java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream)
32: */
33: public void test_ConstructorLjava_io_InputStream() {
34: // Test for method java.util.PropertyResourceBundle(java.io.InputStream)
35: assertTrue("Used to test", true);
36: }
37:
38: /**
39: * @tests java.util.PropertyResourceBundle#getKeys()
40: */
41: public void test_getKeys() {
42: Enumeration keyEnum = prb.getKeys();
43: Vector test = new Vector();
44: int keyCount = 0;
45: while (keyEnum.hasMoreElements()) {
46: test.addElement(keyEnum.nextElement());
47: keyCount++;
48: }
49:
50: assertEquals("Returned the wrong number of keys", 2, keyCount);
51: assertTrue("Returned the wrong keys", test.contains("p1")
52: && test.contains("p2"));
53: }
54:
55: /**
56: * @tests java.util.PropertyResourceBundle#handleGetObject(java.lang.String)
57: */
58: public void test_handleGetObjectLjava_lang_String() {
59: // Test for method java.lang.Object
60: // java.util.PropertyResourceBundle.handleGetObject(java.lang.String)
61: try {
62: assertTrue("Returned incorrect objects", prb
63: .getObject("p1").equals("one")
64: && prb.getObject("p2").equals("two"));
65: } catch (MissingResourceException e) {
66: fail("Threw MisingResourceException for a key contained in the bundle");
67: }
68: try {
69: prb.getObject("Not in the bundle");
70: } catch (MissingResourceException e) {
71: return;
72: }
73: fail("Failed to throw MissingResourceException for object not in the bundle");
74: }
75:
76: /**
77: * Sets up the fixture, for example, open a network connection. This method
78: * is called before a test is executed.
79: */
80: protected void setUp() {
81: java.io.InputStream propertiesStream = new java.io.ByteArrayInputStream(
82: "p1=one\np2=two".getBytes());
83: try {
84: prb = new PropertyResourceBundle(propertiesStream);
85: } catch (java.io.IOException e) {
86: fail("Construction of PropertyResourceBundle threw IOException");
87: }
88: }
89:
90: /**
91: * Tears down the fixture, for example, close a network connection. This
92: * method is called after a test is executed.
93: */
94: protected void tearDown() {
95: }
96: }
|