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 junit.framework.TestCase;
21
22 /***
23 * Tests the StrintConfigurationComparator class
24 *
25 * @version $Revision: 439648 $, $Date: 2006-09-02 22:42:10 +0200 (Sa, 02 Sep 2006) $
26 */
27 public class TestStrictConfigurationComparator extends TestCase
28 {
29 /***
30 * The comparator.
31 */
32 protected ConfigurationComparator comparator = new StrictConfigurationComparator();
33
34 /***
35 * The first configuration.
36 */
37 protected Configuration configuration = new BaseConfiguration();
38
39 /***
40 * Tests the comparator.
41 */
42 public void testCompare()
43 {
44
45 assertTrue(
46 "Compare an empty configuration with itself",
47 comparator.compare(configuration, configuration));
48
49 configuration.setProperty("one", "1");
50 configuration.setProperty("two", "2");
51 configuration.setProperty("three", "3");
52
53
54 assertTrue(
55 "Compare a configuration with itself",
56 comparator.compare(configuration, configuration));
57
58
59 Configuration other = new BaseConfiguration();
60 assertFalse(
61 "Compare a configuration with an empty one",
62 comparator.compare(configuration, other));
63
64 other.setProperty("one", "1");
65 other.setProperty("two", "2");
66 other.setProperty("three", "3");
67
68
69 assertTrue(
70 "Compare a configuration with an identical one",
71 comparator.compare(configuration, other));
72
73 other.setProperty("four", "4");
74 assertFalse(
75 "Compare our configuration with another that has an additional key mapping",
76 comparator.compare(configuration, other));
77
78 configuration.setProperty("four", "4");
79 assertTrue(
80 "Compare our configuration with another that is identical",
81 comparator.compare(configuration, other));
82 }
83
84 public void testCompareNull()
85 {
86 assertTrue(comparator.compare(null, null));
87 assertFalse(comparator.compare(configuration, null));
88 assertFalse(comparator.compare(null, configuration));
89 }
90 }