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