1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import junit.framework.TestCase;
20
21 /***
22 * Tests the StrintConfigurationComparator class
23 *
24 * @version $Revision$, $Date: 2005-02-26 13:56:39 +0100 (Sat, 26 Feb 2005) $
25 */
26 public class TestStrictConfigurationComparator extends TestCase
27 {
28 /***
29 * The comparator.
30 */
31 protected ConfigurationComparator comparator = new StrictConfigurationComparator();
32
33 /***
34 * The first configuration.
35 */
36 protected Configuration configuration = new BaseConfiguration();
37
38 /***
39 * Tests the comparator.
40 */
41 public void testCompare()
42 {
43
44 assertTrue(
45 "Compare an empty configuration with itself",
46 comparator.compare(configuration, configuration));
47
48 configuration.setProperty("one", "1");
49 configuration.setProperty("two", "2");
50 configuration.setProperty("three", "3");
51
52
53 assertTrue(
54 "Compare a configuration with itself",
55 comparator.compare(configuration, configuration));
56
57
58 Configuration other = new BaseConfiguration();
59 assertFalse(
60 "Compare a configuration with an empty one",
61 comparator.compare(configuration, other));
62
63 other.setProperty("one", "1");
64 other.setProperty("two", "2");
65 other.setProperty("three", "3");
66
67
68 assertTrue(
69 "Compare a configuration with an identical one",
70 comparator.compare(configuration, other));
71
72 other.setProperty("four", "4");
73 assertFalse(
74 "Compare our configuration with another that has an additional key mapping",
75 comparator.compare(configuration, other));
76
77 configuration.setProperty("four", "4");
78 assertTrue(
79 "Compare our configuration with another that is identical",
80 comparator.compare(configuration, other));
81 }
82
83 public void testCompareNull()
84 {
85 assertTrue(comparator.compare(null, null));
86 assertFalse(comparator.compare(configuration, null));
87 assertFalse(comparator.compare(null, configuration));
88 }
89 }