KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestConfigurationSet


1 package org.apache.commons.configuration;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import junit.framework.Test;
7 import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9
10 /**
11  * @author rgladwel
12  */

13 public class TestConfigurationSet extends TestCase {
14
15     ConfigurationMap.ConfigurationSet set;
16
17     String JavaDoc[] properties = {
18             "booleanProperty",
19             "doubleProperty",
20             "floatProperty",
21             "intProperty",
22             "longProperty",
23             "shortProperty",
24             "stringProperty"
25     };
26
27     Object JavaDoc[] values = {
28             Boolean.TRUE,
29             new Double JavaDoc(Double.MAX_VALUE),
30             new Float JavaDoc(Float.MAX_VALUE),
31             new Integer JavaDoc(Integer.MAX_VALUE),
32             new Long JavaDoc(Long.MAX_VALUE),
33             new Short JavaDoc(Short.MAX_VALUE),
34             "This is a string"
35     };
36
37     /**
38      * Construct a new instance of this test case.
39      * @param name Name of the test case
40      */

41     public TestConfigurationSet(String JavaDoc name)
42     {
43         super(name);
44     }
45
46     /**
47      * Set up instance variables required by this test case.
48      */

49     public void setUp() throws Exception JavaDoc
50     {
51         BaseConfiguration configuration = new BaseConfiguration();
52         for(int i = 0; i < properties.length ; i++)
53             configuration.setProperty(properties[i], values[i]);
54         set = new ConfigurationMap.ConfigurationSet(configuration);
55     }
56
57     /**
58      * Return the tests included in this test suite.
59      */

60     public static Test suite()
61     {
62         return (new TestSuite(TestConfigurationSet.class));
63     }
64
65     /**
66      * Tear down instance variables required by this test case.
67      */

68     public void tearDown()
69     {
70         set = null;
71     }
72
73     public void testSize() {
74         assertEquals("Entry set does not match properties size.", properties.length, set.size());
75     }
76
77     /**
78      * Class under test for Iterator iterator()
79      */

80     public void testIterator() {
81         Iterator JavaDoc iterator = set.iterator();
82         while(iterator.hasNext()) {
83             Object JavaDoc object = iterator.next();
84             assertTrue("Entry set iterator did not return EntrySet object, returned "
85                     + object.getClass().getName(), object instanceof Map.Entry JavaDoc);
86             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) object;
87             boolean found = false;
88             for(int i = 0; i < properties.length; i++) {
89                 if(entry.getKey().equals(properties[i])) {
90                     assertEquals("Incorrect value for property " +
91                             properties[i],values[i],entry.getValue());
92                     found = true;
93                 }
94             }
95             assertTrue("Could not find property " + entry.getKey(),found);
96             iterator.remove();
97         }
98         assertTrue("Iterator failed to remove all properties.",set.isEmpty());
99     }
100
101 }
102
Popular Tags