001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.configuration; 019 020 import static org.junit.Assert.assertFalse; 021 import static org.junit.Assert.assertTrue; 022 023 import org.junit.Test; 024 025 /** 026 * Tests the StrintConfigurationComparator class 027 * 028 * @version $Id: TestStrictConfigurationComparator.java 1225015 2011-12-27 21:01:59Z oheger $ 029 */ 030 public class TestStrictConfigurationComparator 031 { 032 /** 033 * The comparator. 034 */ 035 protected ConfigurationComparator comparator = new StrictConfigurationComparator(); 036 037 /** 038 * The first configuration. 039 */ 040 protected Configuration configuration = new BaseConfiguration(); 041 042 /** 043 * Tests the comparator. 044 */ 045 @Test 046 public void testCompare() 047 { 048 // Identity comparison for empty configuration 049 assertTrue( 050 "Compare an empty configuration with itself", 051 comparator.compare(configuration, configuration)); 052 053 configuration.setProperty("one", "1"); 054 configuration.setProperty("two", "2"); 055 configuration.setProperty("three", "3"); 056 057 // Identify comparison for non-empty configuration 058 assertTrue( 059 "Compare a configuration with itself", 060 comparator.compare(configuration, configuration)); 061 062 // Create the second configuration 063 Configuration other = new BaseConfiguration(); 064 assertFalse( 065 "Compare a configuration with an empty one", 066 comparator.compare(configuration, other)); 067 068 other.setProperty("one", "1"); 069 other.setProperty("two", "2"); 070 other.setProperty("three", "3"); 071 072 // Two identical, non-empty configurations 073 assertTrue( 074 "Compare a configuration with an identical one", 075 comparator.compare(configuration, other)); 076 077 other.setProperty("four", "4"); 078 assertFalse( 079 "Compare our configuration with another that has an additional key mapping", 080 comparator.compare(configuration, other)); 081 082 configuration.setProperty("four", "4"); 083 assertTrue( 084 "Compare our configuration with another that is identical", 085 comparator.compare(configuration, other)); 086 } 087 088 @Test 089 public void testCompareNull() 090 { 091 assertTrue(comparator.compare(null, null)); 092 assertFalse(comparator.compare(configuration, null)); 093 assertFalse(comparator.compare(null, configuration)); 094 } 095 }