View Javadoc

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 static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertTrue;
22  
23  import org.junit.Test;
24  
25  /**
26   * Tests the StrintConfigurationComparator class
27   *
28   * @version $Id: TestStrictConfigurationComparator.java 1225015 2011-12-27 21:01:59Z oheger $
29   */
30  public class TestStrictConfigurationComparator
31  {
32      /**
33       * The comparator.
34       */
35      protected ConfigurationComparator comparator = new StrictConfigurationComparator();
36  
37      /**
38       * The first configuration.
39       */
40      protected Configuration configuration = new BaseConfiguration();
41  
42      /**
43       * Tests the comparator.
44       */
45      @Test
46      public void testCompare()
47      {
48          // Identity comparison for empty configuration
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          // Identify comparison for non-empty configuration
58          assertTrue(
59              "Compare a configuration with itself",
60              comparator.compare(configuration, configuration));
61  
62          // Create the second configuration
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          // Two identical, non-empty configurations
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  }