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.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import org.junit.jupiter.api.AfterEach;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27
28
29
30 public class TestConfigurationMap {
31
32 private ConfigurationMap map;
33
34 private final String[] properties = {"booleanProperty", "doubleProperty", "floatProperty", "intProperty", "longProperty", "shortProperty",
35 "stringProperty"};
36
37 private final Object[] values = {Boolean.TRUE, Double.valueOf(Double.MAX_VALUE), Float.valueOf(Float.MAX_VALUE), Integer.valueOf(Integer.MAX_VALUE),
38 Long.valueOf(Long.MAX_VALUE), Short.valueOf(Short.MAX_VALUE), "This is a string"};
39
40
41
42
43 @BeforeEach
44 public void setUp() throws Exception {
45 final BaseConfiguration configuration = new BaseConfiguration();
46 for (int i = 0; i < properties.length; i++) {
47 configuration.setProperty(properties[i], values[i]);
48 }
49 map = new ConfigurationMap(configuration);
50 }
51
52
53
54
55 @AfterEach
56 public void tearDown() {
57 map = null;
58 }
59
60
61
62
63 @Test
64 public void testNullConfig() {
65 assertThrows(NullPointerException.class, () -> new ConfigurationMap(null));
66 }
67
68
69
70
71 @Test
72 public void testPut() {
73 for (int i = 0; i < properties.length; i++) {
74 Object object = map.put(properties[i], values[i]);
75 assertNotNull(object);
76 assertEquals(values[i], object);
77 object = map.get(properties[i]);
78 assertNotNull(object);
79 assertEquals(values[i], object);
80 }
81 }
82
83 }