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 private ConfigurationMap.ConfigurationSet set;
35
36 private final String[] properties = {"booleanProperty", "doubleProperty", "floatProperty", "intProperty", "longProperty", "shortProperty",
37 "stringProperty"};
38
39 private final Object[] values = {Boolean.TRUE, Double.valueOf(Double.MAX_VALUE), Float.valueOf(Float.MAX_VALUE), Integer.valueOf(Integer.MAX_VALUE),
40 Long.valueOf(Long.MAX_VALUE), Short.valueOf(Short.MAX_VALUE), "This is a string"};
41
42
43
44
45 @BeforeEach
46 public void setUp() throws Exception {
47 final BaseConfiguration configuration = new BaseConfiguration();
48 for (int i = 0; i < properties.length; i++) {
49 configuration.setProperty(properties[i], values[i]);
50 }
51 set = new ConfigurationMap.ConfigurationSet(configuration);
52 }
53
54
55
56
57 @AfterEach
58 public void tearDown() {
59 set = null;
60 }
61
62
63
64
65 @Test
66 void testIterator() {
67 final Iterator<Map.Entry<Object, Object>> iterator = set.iterator();
68 while (iterator.hasNext()) {
69 final Map.Entry<Object, Object> entry = iterator.next();
70 boolean found = false;
71 for (int i = 0; i < properties.length; i++) {
72 if (entry.getKey().equals(properties[i])) {
73 assertEquals(values[i], entry.getValue(), "Incorrect value for property " + properties[i]);
74 found = true;
75 }
76 }
77 assertTrue(found, "Could not find property " + entry.getKey());
78 iterator.remove();
79 }
80 assertTrue(set.isEmpty());
81 }
82
83 @Test
84 void testSize() {
85 assertEquals(properties.length, set.size());
86 }
87 }