View Javadoc
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 $Id$
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(final 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      @Override
62      protected void setUp() throws Exception {
63  
64          super.setUp();
65  
66          testPropertyWithName = new DynaProperty("test1");
67          testProperty1Duplicate = new DynaProperty("test1");
68  
69          testPropertyWithNameAndType = new DynaProperty("test2", Integer.class);
70          testProperty2Duplicate = new DynaProperty("test2", Integer.class);
71  
72          testPropertyWithNameAndTypeAndContentType = new DynaProperty("test3", Collection.class, Short.class);
73          testProperty3Duplicate = new DynaProperty("test3", Collection.class, Short.class);
74      }
75  
76      /**
77       * Tear down instance variables required by this test case.
78       */
79      @Override
80      protected void tearDown() throws Exception {
81  
82          testPropertyWithName = testProperty1Duplicate = null;
83          testPropertyWithNameAndType = testProperty2Duplicate = null;
84          testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
85          super.tearDown();
86      }
87  
88      /**
89       * Class under test for int hashCode(Object)
90       */
91      public void testHashCode() {
92  
93          final int initialHashCode = testPropertyWithNameAndTypeAndContentType.hashCode();
94          assertEquals(testPropertyWithName.hashCode(), testProperty1Duplicate.hashCode());
95          assertEquals(testPropertyWithNameAndType.hashCode(), testProperty2Duplicate.hashCode());
96          assertEquals(testPropertyWithNameAndTypeAndContentType.hashCode(), testProperty3Duplicate.hashCode());
97          assertEquals(initialHashCode, testPropertyWithNameAndTypeAndContentType.hashCode());
98      }
99  
100     /**
101      * Class under test for boolean equals(Object)
102      */
103     public void testEqualsObject() {
104 
105         assertEquals(testPropertyWithName, testProperty1Duplicate);
106         assertEquals(testPropertyWithNameAndType, testProperty2Duplicate);
107         assertEquals(testPropertyWithNameAndTypeAndContentType, testProperty3Duplicate);
108         assertFalse(testPropertyWithName.equals(testPropertyWithNameAndType));
109         assertFalse(testPropertyWithNameAndType.equals(testPropertyWithNameAndTypeAndContentType));
110         assertFalse(testPropertyWithName.equals(null));
111     }
112 
113 }