PropertyResourceBundleTest.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
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 java.util.Enumeration; 21import java.util.MissingResourceException; 22import java.util.PropertyResourceBundle; 23import java.util.Vector; 24 25public class PropertyResourceBundleTest extends junit.framework.TestCase { 26 27 static PropertyResourceBundle prb; 28 29 /** 30 * @tests java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream) 31 */ 32 public void test_ConstructorLjava_io_InputStream() { 33 // Test for method java.util.PropertyResourceBundle(java.io.InputStream) 34 assertTrue("Used to test", true); 35 } 36 37 /** 38 * @tests java.util.PropertyResourceBundle#getKeys() 39 */ 40 public void test_getKeys() { 41 Enumeration keyEnum = prb.getKeys(); 42 Vector test = new Vector(); 43 int keyCount = 0; 44 while (keyEnum.hasMoreElements()) { 45 test.addElement(keyEnum.nextElement()); 46 keyCount++; 47 } 48 49 assertEquals("Returned the wrong number of keys", 2, keyCount); 50 assertTrue("Returned the wrong keys", test.contains("p1") 51 && test.contains("p2")); 52 } 53 54 /** 55 * @tests java.util.PropertyResourceBundle#handleGetObject(java.lang.String) 56 */ 57 public void test_handleGetObjectLjava_lang_String() { 58 // Test for method java.lang.Object 59 // java.util.PropertyResourceBundle.handleGetObject(java.lang.String) 60 try { 61 assertTrue("Returned incorrect objects", prb.getObject("p1") 62 .equals("one") 63 && prb.getObject("p2").equals("two")); 64 } catch (MissingResourceException e) { 65 fail( 66 "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( 74 "Failed to throw MissingResourceException for object not in the bundle"); 75 } 76 77 /** 78 * Sets up the fixture, for example, open a network connection. This method 79 * is called before a test is executed. 80 */ 81 protected void setUp() { 82 java.io.InputStream propertiesStream = new java.io.ByteArrayInputStream( 83 "p1=one\np2=two".getBytes()); 84 try { 85 prb = new PropertyResourceBundle(propertiesStream); 86 } catch (java.io.IOException e) { 87 fail( 88 "Contruction of PropertyResourceBundle threw IOException"); 89 } 90 } 91 92 /** 93 * Tears down the fixture, for example, close a network connection. This 94 * method is called after a test is executed. 95 */ 96 protected void tearDown() { 97 } 98} 99