KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > common > propertyeditor > PropertiesEditorTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.common.propertyeditor;
19
20 import java.util.Map JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 /**
24  * Unit test for {@link PropertiesEditor} class.
25  *
26  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
27  */

28 public class PropertiesEditorTest extends AbstractMapEditorTest {
29
30     protected void setUp() {
31         editor = PropertyEditors.findEditor(Properties JavaDoc.class);
32     }
33
34     public void testEditorClass() throws Exception JavaDoc {
35         assertEquals(PropertiesEditor.class, editor.getClass());
36     }
37
38     protected void checkType(Object JavaDoc output) {
39         assertTrue("editor returned a: " + output.getClass(), output instanceof Properties JavaDoc);
40     }
41
42     public void testGetValue_1Item() {
43         String JavaDoc input = "key1=value1";
44
45         editor.setAsText(input);
46         Object JavaDoc output = editor.getValue();
47
48         assertNotNull(output);
49         checkType(output);
50
51         Map JavaDoc map = (Map JavaDoc) output;
52         assertEquals(1, map.size());
53         assertEquals("value1", map.get("key1"));
54     }
55
56     public void testGetValue_2Items() {
57         String JavaDoc input = "key1=value1\nkey2=value2";
58
59         editor.setAsText(input);
60         Object JavaDoc output = editor.getValue();
61
62         assertNotNull(output);
63         checkType(output);
64
65         Map JavaDoc map = (Map JavaDoc) output;
66         assertEquals(2, map.size());
67         assertEquals("value1", map.get("key1"));
68         assertEquals("value2", map.get("key2"));
69     }
70     
71     protected Map JavaDoc createMap() {
72         return new Properties JavaDoc();
73     }
74 }
75
Popular Tags