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.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import org.junit.Test;
24
25
26
27
28
29
30 public class TestStrictConfigurationComparator
31 {
32
33
34
35 protected ConfigurationComparator comparator = new StrictConfigurationComparator();
36
37
38
39
40 protected Configuration configuration = new BaseConfiguration();
41
42
43
44
45 @Test
46 public void testCompare()
47 {
48
49 assertTrue(
50 "Compare an empty configuration with itself",
51 comparator.compare(configuration, configuration));
52
53 configuration.setProperty("one", "1");
54 configuration.setProperty("two", "2");
55 configuration.setProperty("three", "3");
56
57
58 assertTrue(
59 "Compare a configuration with itself",
60 comparator.compare(configuration, configuration));
61
62
63 Configuration other = new BaseConfiguration();
64 assertFalse(
65 "Compare a configuration with an empty one",
66 comparator.compare(configuration, other));
67
68 other.setProperty("one", "1");
69 other.setProperty("two", "2");
70 other.setProperty("three", "3");
71
72
73 assertTrue(
74 "Compare a configuration with an identical one",
75 comparator.compare(configuration, other));
76
77 other.setProperty("four", "4");
78 assertFalse(
79 "Compare our configuration with another that has an additional key mapping",
80 comparator.compare(configuration, other));
81
82 configuration.setProperty("four", "4");
83 assertTrue(
84 "Compare our configuration with another that is identical",
85 comparator.compare(configuration, other));
86 }
87
88 @Test
89 public void testCompareNull()
90 {
91 assertTrue(comparator.compare(null, null));
92 assertFalse(comparator.compare(configuration, null));
93 assertFalse(comparator.compare(null, configuration));
94 }
95 }