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.beanutils;
018:
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: import java.util.Collection;
024:
025: /**
026: * Test case for {@link DynaProperty}.
027: *
028: * @version $Revision: 541424 $ $Date: 2007-05-24 21:45:24 +0100 (Thu, 24 May 2007) $
029: */
030: public class DynaPropertyTestCase extends TestCase {
031:
032: private DynaProperty testPropertyWithName;
033: private DynaProperty testProperty1Duplicate;
034: private DynaProperty testPropertyWithNameAndType;
035: private DynaProperty testProperty2Duplicate;
036: private DynaProperty testPropertyWithNameAndTypeAndContentType;
037: private DynaProperty testProperty3Duplicate;
038:
039: /**
040: * Construct a new instance of this test case.
041: *
042: * @param name Name of the test case
043: */
044: public DynaPropertyTestCase(String name) {
045: super (name);
046: }
047:
048: /**
049: * Return the tests included in this test suite.
050: * @return a test suite
051: */
052: public static Test suite() {
053:
054: return (new TestSuite(DynaPropertyTestCase.class));
055:
056: }
057:
058: /**
059: * Set up instance variables required by this test case.
060: */
061: protected void setUp() throws Exception {
062:
063: super .setUp();
064:
065: testPropertyWithName = new DynaProperty("test1");
066: testProperty1Duplicate = new DynaProperty("test1");
067:
068: testPropertyWithNameAndType = new DynaProperty("test2",
069: Integer.class);
070: testProperty2Duplicate = new DynaProperty("test2",
071: Integer.class);
072:
073: testPropertyWithNameAndTypeAndContentType = new DynaProperty(
074: "test3", Collection.class, Short.class);
075: testProperty3Duplicate = new DynaProperty("test3",
076: Collection.class, Short.class);
077: }
078:
079: /**
080: * Tear down instance variables required by this test case.
081: */
082: protected void tearDown() throws Exception {
083:
084: testPropertyWithName = testProperty1Duplicate = null;
085: testPropertyWithNameAndType = testProperty2Duplicate = null;
086: testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
087: super .tearDown();
088: }
089:
090: /**
091: * Class under test for int hashCode(Object)
092: */
093: public void testHashCode() {
094:
095: final int initialHashCode = testPropertyWithNameAndTypeAndContentType
096: .hashCode();
097: assertEquals(testPropertyWithName.hashCode(),
098: testProperty1Duplicate.hashCode());
099: assertEquals(testPropertyWithNameAndType.hashCode(),
100: testProperty2Duplicate.hashCode());
101: assertEquals(testPropertyWithNameAndTypeAndContentType
102: .hashCode(), testProperty3Duplicate.hashCode());
103: assertEquals(initialHashCode,
104: testPropertyWithNameAndTypeAndContentType.hashCode());
105: }
106:
107: /**
108: * Class under test for boolean equals(Object)
109: */
110: public void testEqualsObject() {
111:
112: assertEquals(testPropertyWithName, testProperty1Duplicate);
113: assertEquals(testPropertyWithNameAndType,
114: testProperty2Duplicate);
115: assertEquals(testPropertyWithNameAndTypeAndContentType,
116: testProperty3Duplicate);
117: assertFalse(testPropertyWithName
118: .equals(testPropertyWithNameAndType));
119: assertFalse(testPropertyWithNameAndType
120: .equals(testPropertyWithNameAndTypeAndContentType));
121: assertFalse(testPropertyWithName.equals(null));
122: }
123:
124: }
|