    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    *      http://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  package org.apache.commons.beanutils;
    18
    19  import junit.framework.Test;
    20  import junit.framework.TestCase;
    21  import junit.framework.TestSuite;
    22
    23  import java.util.Collection;
    24
    25  /***
    26   * Test case for {@link DynaProperty}.
    27   *
    28   * @version $Revision: 541424 $ $Date: 2007-05-24 21:45:24 +0100 (Thu, 24 May 2007) $
    29   */
    30  public class DynaPropertyTestCase extends TestCase {
    31
    32  	private DynaProperty testPropertyWithName;
    33  	private DynaProperty testProperty1Duplicate;
    34  	private DynaProperty testPropertyWithNameAndType;
    35  	private DynaProperty testProperty2Duplicate;
    36  	private DynaProperty testPropertyWithNameAndTypeAndContentType;
    37  	private DynaProperty testProperty3Duplicate;
    38
    39      /***
    40       * Construct a new instance of this test case.
    41       *
    42       * @param name Name of the test case
    43       */
    44      public DynaPropertyTestCase(String name) {
    45          super(name);
    46      }
    47
    48      /***
    49       * Return the tests included in this test suite.
    50       * @return a test suite
    51       */
    52      public static Test suite() {
    53
    54          return (new TestSuite(DynaPropertyTestCase.class));
    55
    56      }
    57
    58      /***
    59       * Set up instance variables required by this test case.
    60       */
    61      protected void setUp() throws Exception {
    62
    63  		super.setUp();
    64
    65  		testPropertyWithName = new DynaProperty("test1");
    66  		testProperty1Duplicate = new DynaProperty("test1");
    67
    68  		testPropertyWithNameAndType = new DynaProperty("test2", Integer.class);
    69  		testProperty2Duplicate = new DynaProperty("test2", Integer.class);
    70
    71  		testPropertyWithNameAndTypeAndContentType = new DynaProperty("test3", Collection.class, Short.class);
    72  		testProperty3Duplicate = new DynaProperty("test3", Collection.class, Short.class);
    73  	}
    74
    75      /***
    76       * Tear down instance variables required by this test case.
    77       */
    78  	protected void tearDown() throws Exception {
    79
    80  		testPropertyWithName = testProperty1Duplicate = null;
    81  		testPropertyWithNameAndType = testProperty2Duplicate = null;
    82  		testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
    83  		super.tearDown();
    84  	}
    85
    86      /***
    87  	 * Class under test for int hashCode(Object)
    88  	 */
    89  	public void testHashCode() {
    90
    91  		final int initialHashCode = testPropertyWithNameAndTypeAndContentType.hashCode();
    92  		assertEquals(testPropertyWithName.hashCode(), testProperty1Duplicate.hashCode());
    93  		assertEquals(testPropertyWithNameAndType.hashCode(), testProperty2Duplicate.hashCode());
    94  		assertEquals(testPropertyWithNameAndTypeAndContentType.hashCode(), testProperty3Duplicate.hashCode());
    95  		assertEquals(initialHashCode, testPropertyWithNameAndTypeAndContentType.hashCode());
    96  	}
    97
    98  	/***
    99  	 * Class under test for boolean equals(Object)
    100 	 */
    101 	public void testEqualsObject() {
    102
    103 		assertEquals(testPropertyWithName, testProperty1Duplicate);
    104 		assertEquals(testPropertyWithNameAndType, testProperty2Duplicate);
    105 		assertEquals(testPropertyWithNameAndTypeAndContentType, testProperty3Duplicate);
    106 		assertFalse(testPropertyWithName.equals(testPropertyWithNameAndType));
    107 		assertFalse(testPropertyWithNameAndType.equals(testPropertyWithNameAndTypeAndContentType));
    108         assertFalse(testPropertyWithName.equals(null));
    109 	}
    110
    111 }