1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22
23 import java.util.Iterator;
24 import java.util.Map;
25
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29
30
31
32
33 public class TestConfigurationSet {
34
35 ConfigurationMap.ConfigurationSet set;
36
37 String[] properties = {
38 "booleanProperty",
39 "doubleProperty",
40 "floatProperty",
41 "intProperty",
42 "longProperty",
43 "shortProperty",
44 "stringProperty"
45 };
46
47 Object[] values = {
48 Boolean.TRUE,
49 new Double(Double.MAX_VALUE),
50 new Float(Float.MAX_VALUE),
51 new Integer(Integer.MAX_VALUE),
52 new Long(Long.MAX_VALUE),
53 new Short(Short.MAX_VALUE),
54 "This is a string"
55 };
56
57
58
59
60 @Before
61 public void setUp() throws Exception
62 {
63 BaseConfiguration configuration = new BaseConfiguration();
64 for(int i = 0; i < properties.length ; i++)
65 configuration.setProperty(properties[i], values[i]);
66 set = new ConfigurationMap.ConfigurationSet(configuration);
67 }
68
69
70
71
72 @After
73 public void tearDown()
74 {
75 set = null;
76 }
77
78 @Test
79 public void testSize() {
80 assertEquals("Entry set does not match properties size.", properties.length, set.size());
81 }
82
83
84
85
86 @Test
87 public void testIterator() {
88 Iterator<Map.Entry<Object, Object>> iterator = set.iterator();
89 while(iterator.hasNext()) {
90 Map.Entry<Object, Object> entry = iterator.next();
91 boolean found = false;
92 for(int i = 0; i < properties.length; i++) {
93 if(entry.getKey().equals(properties[i])) {
94 assertEquals("Incorrect value for property " +
95 properties[i],values[i],entry.getValue());
96 found = true;
97 }
98 }
99 assertTrue("Could not find property " + entry.getKey(),found);
100 iterator.remove();
101 }
102 assertTrue("Iterator failed to remove all properties.",set.isEmpty());
103 }
104 }