1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     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      /***
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          // Identity comparison for empty configuration
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          // Identify comparison for non-empty configuration
54          assertTrue(
55              "Compare a configuration with itself",
56              comparator.compare(configuration, configuration));
57  
58          // Create the second configuration
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          // Two identical, non-empty configurations
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  }