1561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/*
2561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  Licensed to the Apache Software Foundation (ASF) under one or more
3561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  contributor license agreements.  See the NOTICE file distributed with
4561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  this work for additional information regarding copyright ownership.
5561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  The ASF licenses this file to You under the Apache License, Version 2.0
6561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  (the "License"); you may not use this file except in compliance with
7561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  the License.  You may obtain a copy of the License at
8561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
9561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *     http://www.apache.org/licenses/LICENSE-2.0
10561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *
11561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  Unless required by applicable law or agreed to in writing, software
12561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  distributed under the License is distributed on an "AS IS" BASIS,
13561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  See the License for the specific language governing permissions and
15561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes *  limitations under the License.
16561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */
17561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
18561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespackage org.apache.harmony.luni.tests.java.util;
19561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
20561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.BufferedReader;
21561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.ByteArrayInputStream;
22561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.ByteArrayOutputStream;
23561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.IOException;
24561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.InputStream;
25561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.InputStreamReader;
26561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.OutputStreamWriter;
27561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.PrintStream;
28561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.PrintWriter;
29561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.Reader;
30561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.Writer;
31561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.ArrayList;
32561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Arrays;
33561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Enumeration;
34561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.InvalidPropertiesFormatException;
35561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Iterator;
36561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.List;
37561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.NoSuchElementException;
38561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Properties;
39561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Scanner;
40561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.util.Set;
41561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
42561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport tests.support.resource.Support_Resources;
43561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
44561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespublic class PropertiesTest extends junit.framework.TestCase {
45561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
46561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    Properties tProps;
47561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
48561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    byte[] propsFile;
49561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
50561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
51561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#Properties()
52561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
53561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_Constructor() {
54561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method java.util.Properties()
55561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties p = new Properties();
56561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // do something to avoid getting a variable unused warning
57561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        p.clear();
58561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Created incorrect Properties", true);
59561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
60561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
61561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_InputStream_NPE() throws Exception {
62561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties p = new Properties();
63561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
64561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            p.load((InputStream) null);
65561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NullPointerException");
66561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e) {
67561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Expected
68561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
69561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
70561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
71561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadsave() throws Exception{
72561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties p = new Properties();
73561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
74561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            p.load((InputStream) null);
75561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NPE");
76561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException npe) {
77561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        	// expected
78561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
79561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
80561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
81561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
82561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#Properties(java.util.Properties)
83561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
84561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_ConstructorLjava_util_Properties() {
85561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties systemProperties = System.getProperties();
86561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties properties = new Properties(systemProperties);
87561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<?> propertyNames = systemProperties.propertyNames();
88561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String propertyName = null;
89561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (propertyNames.hasMoreElements()) {
90561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            propertyName = (String) propertyNames.nextElement();
91561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("failed to construct correct properties",
92561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    systemProperties.get(propertyName), properties
93561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                            .getProperty(propertyName));
94561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
95561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
96561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
97561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
98561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#getProperty(java.lang.String)
99561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
100561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getPropertyLjava_lang_String() {
101561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method java.lang.String
102561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.util.Properties.getProperty(java.lang.String)
103561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Did not retrieve property", "this is a test property",
104561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                ((String) tProps.getProperty("test.prop")));
105561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
106561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
107561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
108561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#getProperty(java.lang.String,
109561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     *        java.lang.String)
110561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
111561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getPropertyLjava_lang_StringLjava_lang_String() {
112561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method java.lang.String
113561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.util.Properties.getProperty(java.lang.String, java.lang.String)
114561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Did not retrieve property", "this is a test property",
115561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                ((String) tProps.getProperty("test.prop", "Blarg")));
116561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Did not return default value", "Gabba", ((String) tProps
117561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("notInThere.prop", "Gabba")));
118561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
119561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
120561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
121561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#getProperty(java.lang.String)
122561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
123561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getPropertyLjava_lang_String2() {
124561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // regression test for HARMONY-3518
125561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        MyProperties props = new MyProperties();
126561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertNull(props.getProperty("key"));
127561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
128561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
129561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
130561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#getProperty(java.lang.String,
131561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     *        java.lang.String)
132561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
133561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_getPropertyLjava_lang_StringLjava_lang_String2() {
134561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // regression test for HARMONY-3518
135561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        MyProperties props = new MyProperties();
136561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("defaultValue", props.getProperty("key", "defaultValue"));
137561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
138561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
139561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    // regression testing for HARMONY-3518
140561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    static class MyProperties extends Properties {
141561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        public synchronized Object get(Object key) {
142561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            return getProperty((String) key); // assume String
143561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
144561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
145561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
146561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
147561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#list(java.io.PrintStream)
148561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
149561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_listLjava_io_PrintStream() {
150561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
151561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        PrintStream ps = new PrintStream(baos);
152561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
153561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Abba", "Cadabra");
154561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Open", "Sesame");
155561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("LongProperty",
156561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "a long long long long long long long property");
157561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.list(ps);
158561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.flush();
159561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String propList = baos.toString();
160561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Property list innacurate",
161561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                propList.indexOf("Abba=Cadabra") >= 0);
162561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Property list innacurate",
163561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                propList.indexOf("Open=Sesame") >= 0);
164561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("property list do not conatins \"...\"", propList
165561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .indexOf("...") != -1);
166561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
167561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps = null;
168561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
169561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.list(ps);
170561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NullPointerException");
171561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e) {
172561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
173561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
174561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
175561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
176561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
177561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#list(java.io.PrintWriter)
178561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
179561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_listLjava_io_PrintWriter() {
180561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
181561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        PrintWriter pw = new PrintWriter(baos);
182561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
183561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Abba", "Cadabra");
184561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Open", "Sesame");
185561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("LongProperty",
186561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "a long long long long long long long property");
187561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.list(pw);
188561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        pw.flush();
189561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String propList = baos.toString();
190561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Property list innacurate",
191561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                propList.indexOf("Abba=Cadabra") >= 0);
192561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Property list innacurate",
193561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                propList.indexOf("Open=Sesame") >= 0);
194561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        pw = null;
195561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
196561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.list(pw);
197561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NullPointerException");
198561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e) {
199561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
200561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
201561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
202561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
203561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
204561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#load(java.io.InputStream)
205561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
206561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_InputStream() {
207561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void java.util.Properties.load(java.io.InputStream)
208561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties prop = null;
209561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
210561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            InputStream is;
211561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop = new Properties();
212561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.load(is = new ByteArrayInputStream(writeProperties()));
213561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is.close();
214561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (Exception e) {
215561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Exception during load test : " + e.getMessage());
216561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
217561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "harmony.tests", prop
218561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("test.pkg"));
219561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertNull("Load failed to parse incorrectly", prop
220561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("commented.entry"));
221561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
222561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
223561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		try {
224561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream("=".getBytes()));
225561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
226561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
227561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
228561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Failed to add empty key", prop.get("").equals(""));
229561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
230561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
231561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
232561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream(" = ".getBytes()));
233561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
234561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
235561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
236561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Failed to add empty key2", prop.get("").equals(""));
237561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
238561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		prop = new Properties();
239561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		try {
240561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream(" a= b".getBytes()));
241561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
242561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
243561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
244561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		assertEquals("Failed to ignore whitespace", "b", prop.get("a"));
245561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
246561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		prop = new Properties();
247561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		try {
248561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream(" a b".getBytes()));
249561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
250561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
251561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
252561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		assertEquals("Failed to interpret whitespace as =", "b", prop.get("a"));
253561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
254561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		prop = new Properties();
255561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		try {
256561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream("#\u008d\u00d2\na=\u008d\u00d3"
257561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes					.getBytes("ISO8859_1")));
258561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
259561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
260561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
261561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		assertEquals("Failed to parse chars >= 0x80", "\u008d\u00d3", prop
262561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes				.get("a"));
263561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
264561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		prop = new Properties();
265561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		try {
266561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			prop.load(new ByteArrayInputStream(
267561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes					"#properties file\r\nfred=1\r\n#last comment"
268561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes							.getBytes("ISO8859_1")));
269561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IOException e) {
270561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			// expected
271561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		} catch (IndexOutOfBoundsException e) {
272561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes			fail("IndexOutOfBoundsException when last line is a comment with no line terminator");
273561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes		}
274561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load when last line contains a comment", "1",
275561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                prop.get("fred"));
276561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
277561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
278561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
279561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes	 * @tests java.util.Properties#load(java.io.InputStream)
280561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes	 */
281561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_InputStream_subtest0() {
282561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
283561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            InputStream is = Support_Resources
284561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getStream("hyts_PropertiesTest.properties");
285561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            Properties props = new Properties();
286561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            props.load(is);
287561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is.close();
288561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("1", "\n \t \f", props.getProperty(" \r"));
289561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("2", "a", props.getProperty("a"));
290561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("3", "bb as,dn   ", props.getProperty("b"));
291561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("4", ":: cu", props.getProperty("c\r \t\nu"));
292561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("5", "bu", props.getProperty("bu"));
293561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("6", "d\r\ne=e", props.getProperty("d"));
294561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("7", "fff", props.getProperty("f"));
295561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("8", "g", props.getProperty("g"));
296561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("9", "", props.getProperty("h h"));
297561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("10", "i=i", props.getProperty(" "));
298561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("11", "   j", props.getProperty("j"));
299561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("12", "   c", props.getProperty("space"));
300561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("13", "\\", props.getProperty("dblbackslash"));
301561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IOException e) {
302561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Unexpected: " + e);
303561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
304561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
305561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
306561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
307561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @throws IOException
308561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#load(java.io.Reader)
309561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
310561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
311561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_Reader() throws IOException {
312561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties prop = null;
313561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
314561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            InputStream is;
315561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop = new Properties();
316561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is = new ByteArrayInputStream(writeProperties());
317561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.load(new InputStreamReader(is));
318561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is.close();
319561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (Exception e) {
320561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Exception during load test : " + e.getMessage());
321561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
322561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "harmony.tests", prop
323561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("test.pkg"));
324561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertNull("Load failed to parse incorrectly", prop
325561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("commented.entry"));
326561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
327561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
328561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("=".getBytes()));
329561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to add empty key", "", prop.get(""));
330561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
331561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
332561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream(" = ".getBytes()));
333561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to add empty key2", "", prop.get(""));
334561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
335561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
336561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream(" a= b".getBytes()));
337561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to ignore whitespace", "b", prop.get("a"));
338561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
339561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
340561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream(" a b".getBytes()));
341561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to interpret whitespace as =", "b", prop.get("a"));
342561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
343561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
344561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("#comment\na=value"
345561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getBytes("UTF-8")));
346561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("value", prop.getProperty("a"));
347561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
348561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
349561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new InputStreamReader(new ByteArrayInputStream(
350561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "#\u008d\u00d2\na=\u008d\u00d3".getBytes("UTF-8"))));
351561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
352561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop
353561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .load(new InputStreamReader(new ByteArrayInputStream(
354561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                            "#\u008d\u00d2\na=\\\\u008d\\\\\\uu00d3"
355561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                                    .getBytes("UTF-8"))));
356561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw IllegalArgumentException");
357561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IllegalArgumentException e) {
358561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
359561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
360561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
361561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
362561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
363561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.load(new InputStreamReader(new ByteArrayInputStream(
364561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    "#properties file\r\nfred=1\r\n#last comment"
365561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                            .getBytes("ISO8859_1"))));
366561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IndexOutOfBoundsException e) {
367561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("IndexOutOfBoundsException when last line is a comment with no line terminator");
368561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
369561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load when last line contains a comment", "1",
370561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                prop.get("fred"));
371561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
372561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Regression tests for HARMONY-5414
373561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
374561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("a=\\u1234z".getBytes()));
375561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
376561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
377561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
378561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.load(new ByteArrayInputStream("a=\\u123".getBytes()));
379561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw IllegalArgumentException");
380561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IllegalArgumentException e) {
381561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Expected
382561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
383561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
384561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
385561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
386561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.load(new ByteArrayInputStream("a=\\u123z".getBytes()));
387561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw IllegalArgumentException");
388561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IllegalArgumentException expected) {
389561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Expected
390561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
391561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
392561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
393561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties expected = new Properties();
394561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        expected.put("a", "\u0000");
395561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("a=\\".getBytes()));
396561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to read trailing slash value", expected, prop);
397561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
398561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
399561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        expected = new Properties();
400561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        expected.put("a", "\u1234\u0000");
401561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("a=\\u1234\\".getBytes()));
402561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to read trailing slash value #2", expected, prop);
403561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
404561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
405561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        expected = new Properties();
406561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        expected.put("a", "q");
407561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("a=\\q".getBytes()));
408561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to read slash value #3", expected, prop);
409561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
410561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
411561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
412561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#load(java.io.InputStream)
413561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
414561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_InputStream_Special() throws IOException {
415561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void java.util.Properties.load(java.io.InputStream)
416561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties prop = null;
417561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
418561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("=".getBytes()));
419561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Failed to add empty key", prop.get("").equals(""));
420561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
421561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
422561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("=\r\n".getBytes()));
423561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Failed to add empty key", prop.get("").equals(""));
424561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
425561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop = new Properties();
426561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        prop.load(new ByteArrayInputStream("=\n\r".getBytes()));
427561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue("Failed to add empty key", prop.get("").equals(""));
428561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
429561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
430561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
431561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @throws IOException
432561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#load(java.io.Reader)
433561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
434561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
435561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_Reader_subtest0() throws IOException {
436561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        InputStream is = Support_Resources
437561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getStream("hyts_PropertiesTest.properties");
438561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
439561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.load(new InputStreamReader(is));
440561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        is.close();
441561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("1", "\n \t \f", props.getProperty(" \r"));
442561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("2", "a", props.getProperty("a"));
443561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("3", "bb as,dn   ", props.getProperty("b"));
444561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("4", ":: cu", props.getProperty("c\r \t\nu"));
445561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("5", "bu", props.getProperty("bu"));
446561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("6", "d\r\ne=e", props.getProperty("d"));
447561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("7", "fff", props.getProperty("f"));
448561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("8", "g", props.getProperty("g"));
449561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("9", "", props.getProperty("h h"));
450561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("10", "i=i", props.getProperty(" "));
451561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("11", "   j", props.getProperty("j"));
452561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("12", "   c", props.getProperty("space"));
453561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("13", "\\", props.getProperty("dblbackslash"));
454561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
455561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
456561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
457561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#propertyNames()
458561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
459561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_propertyNames() {
460561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myPro = new Properties(tProps);
461561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration names = myPro.propertyNames();
462561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        int i = 0;
463561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (names.hasMoreElements()) {
464561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ++i;
465561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            String p = (String) names.nextElement();
466561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue("Incorrect names returned", p.equals("test.prop")
467561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    || p.equals("bogus.prop"));
468561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
469561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
470561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // cast Enumeration to Iterator
471561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Iterator iterator = (Iterator) names;
472561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(iterator.hasNext());
473561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
474561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            iterator.next();
475561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NoSuchElementException");
476561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NoSuchElementException e) {
477561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // Expected
478561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
479561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
480561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
481561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_propertyNames_sequence() {
482561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties parent = new Properties();
483561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.a.key", "parent.a.value");
484561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.b.key", "parent.b.value");
485561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
486561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<?> names = parent.propertyNames();
487561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
488561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
489561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
490561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
491561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties current = new Properties(parent);
492561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.a.key", "current.a.value");
493561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.b.key", "current.b.value");
494561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
495561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        names = current.propertyNames();
496561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
497561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", names.nextElement());
498561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
499561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", names.nextElement());
500561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
501561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
502561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties child = new Properties(current);
503561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.a.key", "child.a.value");
504561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.b.key", "child.b.value");
505561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
506561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        names = child.propertyNames();
507561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
508561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.b.key", names.nextElement());
509561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", names.nextElement());
510561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
511561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.a.key", names.nextElement());
512561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", names.nextElement());
513561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
514561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
515561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
516561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
517561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests {@link java.util.Properties#stringPropertyNames()}
518561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
519561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
520561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_stringPropertyNames() {
521561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Set<String> set = tProps.stringPropertyNames();
522561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(2, set.size());
523561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("test.prop"));
524561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("bogus.prop"));
525561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertNotSame(set, tProps.stringPropertyNames());
526561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
527561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        set = new Properties().stringPropertyNames();
528561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(0, set.size());
529561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
530561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        set = new Properties(System.getProperties()).stringPropertyNames();
531561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.size() > 0);
532561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
533561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps = new Properties(tProps);
534561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put("test.prop", "anotherValue");
535561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put("3rdKey", "3rdValue");
536561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        set = tProps.stringPropertyNames();
537561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(3, set.size());
538561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("test.prop"));
539561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("bogus.prop"));
540561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("3rdKey"));
541561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
542561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put(String.class, "valueOfNonStringKey");
543561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        set = tProps.stringPropertyNames();
544561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(3, set.size());
545561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("test.prop"));
546561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("bogus.prop"));
547561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(set.contains("3rdKey"));
548561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
549561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put("4thKey", "4thValue");
550561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(4, tProps.size());
551561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(3, set.size());
552561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
553561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
554561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            set.add("another");
555561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw UnsupportedOperationException");
556561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (UnsupportedOperationException e) {
557561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
558561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
559561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
560561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
561561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
562561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests {@link java.util.Properties#stringPropertyNames()}
563561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
564561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
565561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_stringPropertyNames_scenario1() {
566561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] keys = new String[] { "key1", "key2", "key3" };
567561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] values = new String[] { "value1", "value2", "value3" };
568561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        List<String> keyList = Arrays.asList(keys);
569561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
570561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties properties = new Properties();
571561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        for (int index = 0; index < keys.length; index++) {
572561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            properties.setProperty(keys[index], values[index]);
573561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
574561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
575561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        properties = new Properties(properties);
576561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Set<String> nameSet = properties.stringPropertyNames();
577561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keys.length, nameSet.size());
578561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Iterator<String> iterator = nameSet.iterator();
579561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (iterator.hasNext()) {
580561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(iterator.next()));
581561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
582561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
583561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<?> nameEnum = properties.propertyNames();
584561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        int count = 0;
585561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (nameEnum.hasMoreElements()) {
586561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            count++;
587561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(nameEnum.nextElement()));
588561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
589561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keys.length, count);
590561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
591561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        properties = new Properties(properties);
592561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameSet = properties.stringPropertyNames();
593561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keys.length, nameSet.size());
594561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        iterator = nameSet.iterator();
595561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (iterator.hasNext()) {
596561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(iterator.next()));
597561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
598561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
599561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameEnum = properties.propertyNames();
600561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        count = 0;
601561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (nameEnum.hasMoreElements()) {
602561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            count++;
603561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(nameEnum.nextElement()));
604561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
605561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keys.length, count);
606561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
607561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
608561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
609561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests {@link java.util.Properties#stringPropertyNames()}
610561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
611561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
612561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_stringPropertyNames_scenario2() {
613561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] defaultKeys = new String[] { "defaultKey1", "defaultKey2",
614561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "defaultKey3", "defaultKey4", "defaultKey5", "defaultKey6" };
615561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] defaultValues = new String[] { "defaultValue1",
616561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "defaultValue2", "defaultValue3", "defaultValue4",
617561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "defaultValue5", "defaultValue6" };
618561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        List<String> keyList = new ArrayList<String>();
619561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties defaults = new Properties();
620561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        for (int index = 0; index < 3; index++) {
621561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            defaults.setProperty(defaultKeys[index], defaultValues[index]);
622561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            keyList.add(defaultKeys[index]);
623561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
624561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
625561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] keys = new String[] { "key1", "key2", "key3" };
626561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String[] values = new String[] { "value1", "value2", "value3" };
627561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties properties = new Properties(defaults);
628561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        for (int index = 0; index < keys.length; index++) {
629561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            properties.setProperty(keys[index], values[index]);
630561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            keyList.add(keys[index]);
631561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
632561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
633561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Set<String> nameSet = properties.stringPropertyNames();
634561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keyList.size(), nameSet.size());
635561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Iterator<String> iterator = nameSet.iterator();
636561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (iterator.hasNext()) {
637561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(iterator.next()));
638561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
639561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
640561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<?> nameEnum = properties.propertyNames();
641561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        int count = 0;
642561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (nameEnum.hasMoreElements()) {
643561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            count++;
644561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(nameEnum.nextElement()));
645561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
646561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keyList.size(), count);
647561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
648561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        for (int index = 3; index < defaultKeys.length; index++) {
649561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            defaults.setProperty(defaultKeys[index], defaultValues[index]);
650561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            keyList.add(defaultKeys[index]);
651561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
652561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
653561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameSet = properties.stringPropertyNames();
654561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keyList.size(), nameSet.size());
655561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        iterator = nameSet.iterator();
656561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (iterator.hasNext()) {
657561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(iterator.next()));
658561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
659561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
660561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameEnum = properties.propertyNames();
661561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        count = 0;
662561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (nameEnum.hasMoreElements()) {
663561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            count++;
664561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue(keyList.contains(nameEnum.nextElement()));
665561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
666561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(keyList.size(), count);
667561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
668561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
669561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
670561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#save(java.io.OutputStream, java.lang.String)
671561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
672561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_saveLjava_io_OutputStreamLjava_lang_String() {
673561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void java.util.Properties.save(java.io.OutputStream,
674561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.lang.String)
675561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
676561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps2 = new Properties();
677561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
678561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Property A", "aye");
679561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Property B", "bee");
680561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Property C", "see");
681561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
682561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
683561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayOutputStream out = new ByteArrayOutputStream();
684561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.save(out, "A Header");
685561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            out.close();
686561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayInputStream in = new ByteArrayInputStream(out
687561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .toByteArray());
688561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps2.load(in);
689561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            in.close();
690561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IOException ioe) {
691561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("IOException occurred reading/writing file : "
692561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ioe.getMessage());
693561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
694561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
695561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration e = myProps.propertyNames();
696561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String nextKey;
697561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (e.hasMoreElements()) {
698561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            nextKey = (String) e.nextElement();
699561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals("Stored property list not equal to original", myProps
700561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getProperty(nextKey), myProps2.getProperty(nextKey));
701561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
702561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
703561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
704561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
705561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#setProperty(java.lang.String,
706561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     *        java.lang.String)
707561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
708561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_setPropertyLjava_lang_StringLjava_lang_String() {
709561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method java.lang.Object
710561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.util.Properties.setProperty(java.lang.String, java.lang.String)
711561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
712561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Yoink", "Yabba");
713561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to set property", "Yabba", myProps
714561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("Yoink"));
715561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("Yoink", "Gab");
716561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to reset property", "Gab", myProps
717561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("Yoink"));
718561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
719561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
720561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
721561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#store(java.io.OutputStream, java.lang.String)
722561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
723561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_storeLjava_io_OutputStreamLjava_lang_String() {
724561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void java.util.Properties.store(java.io.OutputStream,
725561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.lang.String)
726561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
727561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps2 = new Properties();
728561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration e;
729561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String nextKey;
730561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
731561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property A", " aye\\\f\t\n\r\b");
732561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property B", "b ee#!=:");
733561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property C", "see");
734561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
735561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
736561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayOutputStream out = new ByteArrayOutputStream();
737561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.store(out, "A Header");
738561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            out.close();
739561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayInputStream in = new ByteArrayInputStream(out
740561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .toByteArray());
741561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps2.load(in);
742561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            in.close();
743561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IOException ioe) {
744561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("IOException occurred reading/writing file : "
745561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ioe.getMessage());
746561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
747561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
748561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        e = myProps.propertyNames();
749561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (e.hasMoreElements()) {
750561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            nextKey = (String) e.nextElement();
751561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue("Stored property list not equal to original", myProps2
752561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
753561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
754561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
755561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
756561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
757561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
758561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @throws IOException
759561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#store(java.io.Writer, java.lang.String)
760561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @since 1.6
761561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
762561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_storeLjava_io_WriterLjava_lang_String() throws IOException {
763561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
764561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps2 = new Properties();
765561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
766561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property A", " aye\\\f\t\n\r\b");
767561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property B", "b ee#!=:");
768561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("Property C", "see");
769561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
770561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream out = new ByteArrayOutputStream();
771561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.store(new OutputStreamWriter(out), "A Header");
772561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Scanner scanner = new Scanner(out.toString());
773561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(scanner.nextLine().startsWith("#A Header"));
774561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertTrue(scanner.nextLine().startsWith("#"));
775561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        out.close();
776561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
777561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps2.load(in);
778561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        in.close();
779561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
780561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration e = myProps.propertyNames();
781561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String nextKey;
782561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (e.hasMoreElements()) {
783561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            nextKey = (String) e.nextElement();
784561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue("Stored property list not equal to original", myProps2
785561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
786561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
787561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
788561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
789561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.store((Writer) null, "some comments");
790561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw NullPointerException");
791561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e1) {
792561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
793561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
794561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
795561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put(String.class, "wrong type");
796561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
797561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.store(new OutputStreamWriter(new ByteArrayOutputStream()),
798561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    "some comments");
799561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw ClassCastException");
800561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (ClassCastException e1) {
801561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
802561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
803561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.remove(String.class);
804561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.store(new OutputStreamWriter(new ByteArrayOutputStream()),
805561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "some comments");
806561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // it is OK
807561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.put("wrong type", String.class);
808561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
809561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.store(new OutputStreamWriter(new ByteArrayOutputStream()),
810561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    "some comments");
811561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Should throw ClassCastException");
812561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (ClassCastException e1) {
813561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
814561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
815561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
816561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
817561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
818561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#loadFromXML(java.io.InputStream)
819561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
820561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadFromXMLLjava_io_InputStream() throws Exception {
821561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void
822561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.util.Properties.loadFromXML(java.io.InputStream)
823561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties prop = null;
824561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
825561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            InputStream is;
826561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop = new Properties();
827561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.loadFromXML(is = new ByteArrayInputStream(
828561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    writePropertiesXMLUTF_8()));
829561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is.close();
830561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (Exception e) {
831561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Exception during load test : " + e.getMessage());
832561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
833561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "value3", prop
834561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("key3"));
835561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "value1", prop
836561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("key1"));
837561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
838561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
839561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            InputStream is;
840561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop = new Properties();
841561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.loadFromXML(is = new ByteArrayInputStream(
842561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    writePropertiesXMLISO_8859_1()));
843561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            is.close();
844561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (Exception e) {
845561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("Exception during load test : " + e.getMessage());
846561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
847561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "value2", prop
848561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("key2"));
849561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("Failed to load correct properties", "value1", prop
850561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .getProperty("key1"));
851561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
852561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
853561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            prop.loadFromXML(null);
854561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw NullPointerException");
855561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException e) {
856561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
857561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
858561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
859561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
860561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
861561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * @tests java.util.Properties#storeToXML(java.io.OutputStream,
862561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     *        java.lang.String, java.lang.String)
863561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
864561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_storeToXMLLjava_io_OutputStreamLjava_lang_StringLjava_lang_String()
865561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            throws Exception {
866561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // Test for method void
867561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.util.Properties.storeToXML(java.io.OutputStream,
868561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        // java.lang.String, java.lang.String)
869561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps = new Properties();
870561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties myProps2 = new Properties();
871561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration e;
872561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        String nextKey;
873561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
874561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key1", "value1");
875561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key2", "value2");
876561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key3", "value3");
877561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("<a>key4</a>", "\"value4");
878561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key5   ", "<h>value5</h>");
879561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("<a>key6</a>", "   <h>value6</h>   ");
880561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("<comment>key7</comment>", "value7");
881561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("  key8   ", "<comment>value8</comment>");
882561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("&lt;key9&gt;", "\u0027value9");
883561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key10\"", "&lt;value10&gt;");
884561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("&amp;key11&amp;", "value11");
885561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("key12", "&amp;value12&amp;");
886561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        myProps.setProperty("<a>&amp;key13&lt;</a>",
887561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "&amp;&value13<b>&amp;</b>");
888561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
889561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
890561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayOutputStream out = new ByteArrayOutputStream();
891561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
892561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // store in UTF-8 encoding
893561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.storeToXML(out, "comment");
894561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            out.close();
895561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayInputStream in = new ByteArrayInputStream(out
896561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .toByteArray());
897561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps2.loadFromXML(in);
898561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            in.close();
899561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (InvalidPropertiesFormatException ipfe) {
900561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("InvalidPropertiesFormatException occurred reading file: "
901561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ipfe.getMessage());
902561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IOException ioe) {
903561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("IOException occurred reading/writing file : "
904561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ioe.getMessage());
905561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
906561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
907561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        e = myProps.propertyNames();
908561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (e.hasMoreElements()) {
909561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            nextKey = (String) e.nextElement();
910561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue("Stored property list not equal to original", myProps2
911561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
912561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
913561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
914561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
915561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayOutputStream out = new ByteArrayOutputStream();
916561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
917561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // store in ISO-8859-1 encoding
918561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.storeToXML(out, "comment", "ISO-8859-1");
919561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            out.close();
920561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayInputStream in = new ByteArrayInputStream(out
921561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .toByteArray());
922561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps2 = new Properties();
923561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps2.loadFromXML(in);
924561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            in.close();
925561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (InvalidPropertiesFormatException ipfe) {
926561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("InvalidPropertiesFormatException occurred reading file: "
927561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ipfe.getMessage());
928561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (IOException ioe) {
929561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("IOException occurred reading/writing file : "
930561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    + ioe.getMessage());
931561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
932561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
933561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        e = myProps.propertyNames();
934561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        while (e.hasMoreElements()) {
935561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            nextKey = (String) e.nextElement();
936561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertTrue("Stored property list not equal to original", myProps2
937561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                    .getProperty(nextKey).equals(myProps.getProperty(nextKey)));
938561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
939561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
940561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        try {
941561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            ByteArrayOutputStream out = new ByteArrayOutputStream();
942561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            myProps.storeToXML(out, null, null);
943561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should throw nullPointerException");
944561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        } catch (NullPointerException ne) {
945561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            // expected
946561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
947561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
948561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
949561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
950561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * if loading from single line like "hello" without "\n\r" neither "=", it
951561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * should be same as loading from "hello="
952561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
953561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testLoadSingleLine() throws Exception{
954561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
955561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        InputStream sr = new ByteArrayInputStream("hello".getBytes());
956561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.load(sr);
957561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(1, props.size());
958561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
959561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
960561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_SequentialpropertyNames() {
961561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties parent = new Properties();
962561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.a.key", "parent.a.value");
963561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.b.key", "parent.b.value");
964561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
965561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<?> names = parent.propertyNames();
966561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
967561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
968561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
969561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
970561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties current = new Properties(parent);
971561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.a.key", "current.a.value");
972561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.b.key", "current.b.value");
973561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
974561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        names = current.propertyNames();
975561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
976561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", names.nextElement());
977561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
978561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", names.nextElement());
979561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
980561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
981561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties child = new Properties(current);
982561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.a.key", "child.a.value");
983561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.b.key", "child.b.value");
984561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
985561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        names = child.propertyNames();
986561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", names.nextElement());
987561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.b.key", names.nextElement());
988561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", names.nextElement());
989561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", names.nextElement());
990561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.a.key", names.nextElement());
991561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", names.nextElement());
992561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(names.hasMoreElements());
993561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
994561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
995561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_SequentialstringPropertyNames() {
996561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties parent = new Properties();
997561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.a.key", "parent.a.value");
998561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        parent.setProperty("parent.b.key", "parent.b.value");
999561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1000561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Iterator<String> nameIterator = parent.stringPropertyNames().iterator();
1001561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", nameIterator.next());
1002561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", nameIterator.next());
1003561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(nameIterator.hasNext());
1004561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1005561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties current = new Properties(parent);
1006561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.a.key", "current.a.value");
1007561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        current.setProperty("current.b.key", "current.b.value");
1008561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1009561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameIterator = current.stringPropertyNames().iterator();
1010561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", nameIterator.next());
1011561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", nameIterator.next());
1012561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", nameIterator.next());
1013561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", nameIterator.next());
1014561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(nameIterator.hasNext());
1015561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1016561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties child = new Properties(current);
1017561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.a.key", "child.a.value");
1018561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        child.setProperty("child.b.key", "child.b.value");
1019561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1020561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        nameIterator = child.stringPropertyNames().iterator();
1021561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.a.key", nameIterator.next());
1022561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.b.key", nameIterator.next());
1023561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.b.key", nameIterator.next());
1024561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("parent.b.key", nameIterator.next());
1025561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("child.a.key", nameIterator.next());
1026561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("current.a.key", nameIterator.next());
1027561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(nameIterator.hasNext());
1028561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1029561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1030561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public static class MockProperties extends Properties {
1031561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1032561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        private static final long serialVersionUID = 1L;
1033561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1034561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        public MockProperties() throws IOException {
1035561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            mockLoad();
1036561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
1037561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1038561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        private void mockLoad() throws IOException {
1039561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            super.load(new ByteArrayInputStream("key=value".getBytes()));
1040561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
1041561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1042561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        public void load(Reader reader) {
1043561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            fail("should invoke Properties.load(Reader)");
1044561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
1045561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1046561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1047561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void test_loadLjava_io_InputStream_onLjava_io_Reader()
1048561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            throws IOException {
1049561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        MockProperties mockProperties = new MockProperties();
1050561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals(1, mockProperties.size());
1051561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("value", mockProperties.get("key"));
1052561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1053561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1054561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    private String comment1 = "comment1";
1055561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1056561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    private String comment2 = "comment2";
1057561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1058561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    private void validateOutput(String[] expectStrings, byte[] output)
1059561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            throws IOException {
1060561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayInputStream bais = new ByteArrayInputStream(output);
1061561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        BufferedReader br = new BufferedReader(new InputStreamReader(bais,
1062561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "ISO8859_1"));
1063561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        for (String expectString : expectStrings) {
1064561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes            assertEquals(expectString, br.readLine());
1065561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        }
1066561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        br.readLine();
1067561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertNull(br.readLine());
1068561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        br.close();
1069561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1070561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1071561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario0() throws IOException {
1072561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1073561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1074561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + comment2);
1075561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1076561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1077561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1078561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1079561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1080561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario1() throws IOException {
1081561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1082561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1083561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + comment2);
1084561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1085561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1086561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1087561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1088561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1089561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario2() throws IOException {
1090561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1091561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1092561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + '\n' + comment2);
1093561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1094561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1095561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1096561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1097561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1098561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario3() throws IOException {
1099561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1100561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1101561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + '\r' + comment2);
1102561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#", "#comment2" },
1103561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1104561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1105561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1106561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1107561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario4() throws IOException {
1108561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1109561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1110561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + '#' + comment2);
1111561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1112561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1113561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1114561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1115561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1116561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario5() throws IOException {
1117561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1118561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1119561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + '!' + comment2);
1120561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "!comment2" },
1121561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1122561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1123561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1124561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1125561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario6() throws IOException {
1126561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1127561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1128561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + '#' + comment2);
1129561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1130561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1131561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1132561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1133561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1134561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario7() throws IOException {
1135561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1136561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1137561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + '!' + comment2);
1138561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "!comment2" },
1139561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1140561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1141561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1142561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1143561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario8() throws IOException {
1144561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1145561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1146561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + '\n' + '#' + comment2);
1147561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#comment2" },
1148561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1149561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1150561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1151561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1152561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario9() throws IOException {
1153561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1154561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1155561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + '\r' + '#' + comment2);
1156561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#", "#comment2" },
1157561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1158561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1159561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1160561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1161561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario10() throws IOException {
1162561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1163561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1164561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\r' + '\n' + '!' + comment2);
1165561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "!comment2" },
1166561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1167561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1168561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1169561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1170561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testStore_scenario11() throws IOException {
1171561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1172561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1173561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.store(baos, comment1 + '\n' + '\r' + '!' + comment2);
1174561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        validateOutput(new String[] { "#comment1", "#", "!comment2" },
1175561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                baos.toByteArray());
1176561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        baos.close();
1177561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1178561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1179561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    public void testLoadReader() throws IOException {
1180561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        InputStream inputStream = new ByteArrayInputStream(
1181561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "\u3000key=value".getBytes("UTF-8"));
1182561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Properties props = new Properties();
1183561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.load(inputStream);
1184561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        Enumeration<Object> keyEnum = props.keys();
1185561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse("\u3000key".equals(keyEnum.nextElement()));
1186561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(keyEnum.hasMoreElements());
1187561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        inputStream.close();
1188561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1189561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        inputStream = new ByteArrayInputStream(
1190561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                "\u3000key=value".getBytes("UTF-8"));
1191561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props = new Properties();
1192561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        props.load(new InputStreamReader(inputStream, "UTF-8"));
1193561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        keyEnum = props.keys();
1194561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertEquals("\u3000key", keyEnum.nextElement());
1195561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        assertFalse(keyEnum.hasMoreElements());
1196561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        inputStream.close();
1197561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1198561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1199561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
1200561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * Sets up the fixture, for example, open a network connection. This method
1201561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * is called before a test is executed.
1202561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
1203561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    protected void setUp() {
1204561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1205561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps = new Properties();
1206561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put("test.prop", "this is a test property");
1207561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        tProps.put("bogus.prop", "bogus");
1208561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1209561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1210561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
1211561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * Tears down the fixture, for example, close a network connection. This
1212561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * method is called after a test is executed.
1213561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
1214561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    protected void tearDown() {
1215561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1216561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1217561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    /**
1218561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * Tears down the fixture, for example, close a network connection. This
1219561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     * method is called after a test is executed.
1220561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes     */
1221561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    protected byte[] writeProperties() throws IOException {
1222561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        PrintStream ps = null;
1223561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream bout = new ByteArrayOutputStream();
1224561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps = new PrintStream(bout);
1225561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("#commented.entry=Bogus");
1226561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("test.pkg=harmony.tests");
1227561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("test.proj=Automated Tests");
1228561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.close();
1229561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        return bout.toByteArray();
1230561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1231561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1232561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    protected byte[] writePropertiesXMLUTF_8() throws IOException {
1233561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        PrintStream ps = null;
1234561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream bout = new ByteArrayOutputStream();
1235561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps = new PrintStream(bout, true, "UTF-8");
1236561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1237561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps
1238561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .println("<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">");
1239561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<properties>");
1240561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<comment>comment</comment>");
1241561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key4\">value4</entry>");
1242561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key3\">value3</entry>");
1243561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key2\">value2</entry>");
1244561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key1\"><!-- xml comment -->value1</entry>");
1245561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("</properties>");
1246561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.close();
1247561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        return bout.toByteArray();
1248561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1249561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes
1250561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    protected byte[] writePropertiesXMLISO_8859_1() throws IOException {
1251561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        PrintStream ps = null;
1252561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ByteArrayOutputStream bout = new ByteArrayOutputStream();
1253561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps = new PrintStream(bout, true, "ISO-8859-1");
1254561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
1255561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps
1256561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes                .println("<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">");
1257561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<properties>");
1258561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<comment>comment</comment>");
1259561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key4\">value4</entry>");
1260561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key3\">value3</entry>");
1261561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key2\">value2</entry>");
1262561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("<entry key=\"key1\"><!-- xml comment -->value1</entry>");
1263561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.println("</properties>");
1264561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        ps.close();
1265561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes        return bout.toByteArray();
1266561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes    }
1267561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes}
1268