01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * 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: // Identity comparison for empty configuration
43: assertTrue("Compare an empty configuration with itself",
44: comparator.compare(configuration, configuration));
45:
46: configuration.setProperty("one", "1");
47: configuration.setProperty("two", "2");
48: configuration.setProperty("three", "3");
49:
50: // Identify comparison for non-empty configuration
51: assertTrue("Compare a configuration with itself", comparator
52: .compare(configuration, configuration));
53:
54: // Create the second configuration
55: Configuration other = new BaseConfiguration();
56: assertFalse("Compare a configuration with an empty one",
57: comparator.compare(configuration, other));
58:
59: other.setProperty("one", "1");
60: other.setProperty("two", "2");
61: other.setProperty("three", "3");
62:
63: // Two identical, non-empty configurations
64: assertTrue("Compare a configuration with an identical one",
65: comparator.compare(configuration, other));
66:
67: other.setProperty("four", "4");
68: assertFalse(
69: "Compare our configuration with another that has an additional key mapping",
70: comparator.compare(configuration, other));
71:
72: configuration.setProperty("four", "4");
73: assertTrue(
74: "Compare our configuration with another that is identical",
75: comparator.compare(configuration, other));
76: }
77:
78: public void testCompareNull() {
79: assertTrue(comparator.compare(null, null));
80: assertFalse(comparator.compare(configuration, null));
81: assertFalse(comparator.compare(null, configuration));
82: }
83: }
|