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.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.util.Iterator;
26
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class TestEnvironmentConfiguration {
34
35 private EnvironmentConfiguration config;
36
37 @BeforeEach
38 public void setUp() throws Exception {
39 config = new EnvironmentConfiguration();
40 }
41
42
43
44
45 @Test
46 public void testAddProperty() {
47 assertThrows(UnsupportedOperationException.class, () -> config.addProperty("JAVA_HOME", "C:\\java"));
48 }
49
50
51
52
53 @Test
54 public void testClear() {
55 assertThrows(UnsupportedOperationException.class, config::clear);
56 }
57
58
59
60
61 @Test
62 public void testClearProperty() {
63 final String key = config.getKeys().next();
64 assertThrows(UnsupportedOperationException.class, () -> config.clearProperty(key));
65 }
66
67
68
69
70
71 @Test
72 public void testInit() {
73 boolean found = false;
74 assertFalse(config.isEmpty());
75 for (final Iterator<String> it = config.getKeys(); it.hasNext();) {
76 final String key = it.next();
77 assertTrue(config.containsKey(key), "Key not found: " + key);
78 assertNotNull(config.getString(key), "No value for property " + key);
79 found = true;
80 }
81 assertTrue(found);
82 }
83
84
85
86
87 @Test
88 public void testSetProperty() {
89 assertThrows(UnsupportedOperationException.class, () -> config.setProperty("JAVA_HOME", "C:\\java"));
90 }
91 }