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    *     https://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.configuration2;
19  
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import org.junit.jupiter.api.Test;
24  
25  /**
26   * Tests the StrintConfigurationComparator class
27   */
28  public class TestStrictConfigurationComparator {
29  
30      /**
31       * The comparator.
32       */
33      protected ConfigurationComparator comparator = new StrictConfigurationComparator();
34  
35      /**
36       * The first configuration.
37       */
38      protected Configuration configuration = new BaseConfiguration();
39  
40      /**
41       * Tests the comparator.
42       */
43      @Test
44      void testCompare() {
45          // Identity comparison for empty configuration
46          assertTrue(comparator.compare(configuration, configuration));
47  
48          configuration.setProperty("one", "1");
49          configuration.setProperty("two", "2");
50          configuration.setProperty("three", "3");
51  
52          // Identify comparison for non-empty configuration
53          assertTrue(comparator.compare(configuration, configuration));
54  
55          // Create the second configuration
56          final Configuration other = new BaseConfiguration();
57          assertFalse(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(comparator.compare(configuration, other));
65  
66          other.setProperty("four", "4");
67          assertFalse(comparator.compare(configuration, other));
68  
69          configuration.setProperty("four", "4");
70          assertTrue(comparator.compare(configuration, other));
71      }
72  
73      @Test
74      void testCompareNull() {
75          assertTrue(comparator.compare(null, null));
76          assertFalse(comparator.compare(configuration, null));
77          assertFalse(comparator.compare(null, configuration));
78      }
79  }