KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestStrictConfigurationComparator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration;
18
19 import junit.framework.TestCase;
20
21 /**
22  * Tests the StrintConfigurationComparator class
23  *
24  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
25  */

26 public class TestStrictConfigurationComparator extends TestCase
27 {
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     {
43         // Identity comparison for empty configuration
44
assertTrue(
45             "Compare an empty configuration with itself",
46             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(
54             "Compare a configuration with itself",
55             comparator.compare(configuration, configuration));
56
57         // Create the second configuration
58
Configuration other = new BaseConfiguration();
59         assertFalse(
60             "Compare a configuration with an empty one",
61             comparator.compare(configuration, other));
62
63         other.setProperty("one", "1");
64         other.setProperty("two", "2");
65         other.setProperty("three", "3");
66
67         // Two identical, non-empty configurations
68
assertTrue(
69             "Compare a configuration with an identical one",
70             comparator.compare(configuration, other));
71
72         other.setProperty("four", "4");
73         assertFalse(
74             "Compare our configuration with another that has an additional key mapping",
75             comparator.compare(configuration, other));
76
77         configuration.setProperty("four", "4");
78         assertTrue(
79             "Compare our configuration with another that is identical",
80             comparator.compare(configuration, other));
81     }
82
83     public void testCompareNull()
84     {
85         assertTrue(comparator.compare(null, null));
86         assertFalse(comparator.compare(configuration, null));
87         assertFalse(comparator.compare(null, configuration));
88     }
89 }
90
Popular Tags