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    *      https://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.beanutils2;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  
22  import java.util.Collection;
23  
24  import org.junit.jupiter.api.AfterEach;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * Test case for {@link DynaProperty}.
30   */
31  public class DynaPropertyTest {
32  
33      private DynaProperty testPropertyWithName;
34      private DynaProperty testProperty1Duplicate;
35      private DynaProperty testPropertyWithNameAndType;
36      private DynaProperty testProperty2Duplicate;
37      private DynaProperty testPropertyWithNameAndTypeAndContentType;
38  
39      private DynaProperty testProperty3Duplicate;
40  
41      /**
42       * Sets up instance variables required by this test case.
43       */
44      @BeforeEach
45      protected void setUp() throws Exception {
46  
47          testPropertyWithName = new DynaProperty("test1");
48          testProperty1Duplicate = new DynaProperty("test1");
49  
50          testPropertyWithNameAndType = new DynaProperty("test2", Integer.class);
51          testProperty2Duplicate = new DynaProperty("test2", Integer.class);
52  
53          testPropertyWithNameAndTypeAndContentType = new DynaProperty("test3", Collection.class, Short.class);
54          testProperty3Duplicate = new DynaProperty("test3", Collection.class, Short.class);
55      }
56  
57      /**
58       * Tear down instance variables required by this test case.
59       */
60      @AfterEach
61      protected void tearDown() throws Exception {
62  
63          testPropertyWithName = testProperty1Duplicate = null;
64          testPropertyWithNameAndType = testProperty2Duplicate = null;
65          testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
66      }
67  
68      /**
69       * Class under test for boolean equals(Object)
70       */
71      @Test
72      public void testEqualsObject() {
73  
74          assertEquals(testPropertyWithName, testProperty1Duplicate);
75          assertEquals(testPropertyWithNameAndType, testProperty2Duplicate);
76          assertEquals(testPropertyWithNameAndTypeAndContentType, testProperty3Duplicate);
77          assertFalse(testPropertyWithName.equals(testPropertyWithNameAndType));
78          assertFalse(testPropertyWithNameAndType.equals(testPropertyWithNameAndTypeAndContentType));
79          assertFalse(testPropertyWithName.equals(null));
80      }
81  
82      /**
83       * Class under test for int hashCode(Object)
84       */
85      @Test
86      public void testHashCode() {
87  
88          final int initialHashCode = testPropertyWithNameAndTypeAndContentType.hashCode();
89          assertEquals(testPropertyWithName.hashCode(), testProperty1Duplicate.hashCode());
90          assertEquals(testPropertyWithNameAndType.hashCode(), testProperty2Duplicate.hashCode());
91          assertEquals(testPropertyWithNameAndTypeAndContentType.hashCode(), testProperty3Duplicate.hashCode());
92          assertEquals(initialHashCode, testPropertyWithNameAndTypeAndContentType.hashCode());
93      }
94  
95  }