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: package org.apache.commons.configuration;
018:
019: import java.util.Iterator;
020: import java.util.Map;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: /**
027: * @author rgladwel
028: */
029: public class TestConfigurationSet extends TestCase {
030:
031: ConfigurationMap.ConfigurationSet set;
032:
033: String[] properties = { "booleanProperty", "doubleProperty",
034: "floatProperty", "intProperty", "longProperty",
035: "shortProperty", "stringProperty" };
036:
037: Object[] values = { Boolean.TRUE, new Double(Double.MAX_VALUE),
038: new Float(Float.MAX_VALUE), new Integer(Integer.MAX_VALUE),
039: new Long(Long.MAX_VALUE), new Short(Short.MAX_VALUE),
040: "This is a string" };
041:
042: /**
043: * Construct a new instance of this test case.
044: * @param name Name of the test case
045: */
046: public TestConfigurationSet(String name) {
047: super (name);
048: }
049:
050: /**
051: * Set up instance variables required by this test case.
052: */
053: public void setUp() throws Exception {
054: BaseConfiguration configuration = new BaseConfiguration();
055: for (int i = 0; i < properties.length; i++)
056: configuration.setProperty(properties[i], values[i]);
057: set = new ConfigurationMap.ConfigurationSet(configuration);
058: }
059:
060: /**
061: * Return the tests included in this test suite.
062: */
063: public static Test suite() {
064: return (new TestSuite(TestConfigurationSet.class));
065: }
066:
067: /**
068: * Tear down instance variables required by this test case.
069: */
070: public void tearDown() {
071: set = null;
072: }
073:
074: public void testSize() {
075: assertEquals("Entry set does not match properties size.",
076: properties.length, set.size());
077: }
078:
079: /**
080: * Class under test for Iterator iterator()
081: */
082: public void testIterator() {
083: Iterator iterator = set.iterator();
084: while (iterator.hasNext()) {
085: Object object = iterator.next();
086: assertTrue(
087: "Entry set iterator did not return EntrySet object, returned "
088: + object.getClass().getName(),
089: object instanceof Map.Entry);
090: Map.Entry entry = (Map.Entry) object;
091: boolean found = false;
092: for (int i = 0; i < properties.length; i++) {
093: if (entry.getKey().equals(properties[i])) {
094: assertEquals("Incorrect value for property "
095: + properties[i], values[i], entry
096: .getValue());
097: found = true;
098: }
099: }
100: assertTrue("Could not find property " + entry.getKey(),
101: found);
102: iterator.remove();
103: }
104: assertTrue("Iterator failed to remove all properties.", set
105: .isEmpty());
106: }
107:
108: }
|