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.bugs;
18  
19  import static org.junit.jupiter.api.Assertions.assertThrows;
20  
21  import org.apache.commons.beanutils2.PropertyUtils;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.junit.jupiter.api.AfterEach;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-349">https://issues.apache.org/jira/browse/BEANUTILS-349</a>
30   */
31  public class Jira349Test {
32  
33      /**
34       * Test Bean with a Boolean object property.
35       */
36      public static class ObjectBean {
37          private Boolean testProperty;
38  
39          public Boolean getTestProperty() {
40              return testProperty;
41          }
42  
43          public void setTestProperty(final Boolean testProperty) {
44              this.testProperty = testProperty;
45          }
46      }
47  
48      /**
49       * Test Bean with a primitive boolean property.
50       */
51      public static class PrimitiveBean {
52          private boolean testProperty;
53  
54          public boolean getTestProperty() {
55              return testProperty;
56          }
57  
58          public void setTestProperty(final boolean testProperty) {
59              this.testProperty = testProperty;
60          }
61      }
62  
63      private static final Log LOG = LogFactory.getLog(Jira349Test.class);
64  
65      /**
66       * Sets up.
67       *
68       * @throws Exception
69       */
70      @BeforeEach
71      protected void setUp() throws Exception {
72      }
73  
74      /**
75       * Tear Down.
76       *
77       * @throws Exception
78       */
79      @AfterEach
80      protected void tearDown() throws Exception {
81      }
82  
83      /**
84       * Test {@link PropertyUtils#copyProperties(Object, Object)}
85       */
86      @Test
87      public void testIssue_BEANUTILS_349_PropertyUtils_copyProperties() {
88          final PrimitiveBean dest = new PrimitiveBean();
89          final ObjectBean origin = new ObjectBean();
90          assertThrows(IllegalArgumentException.class, () -> PropertyUtils.copyProperties(dest, origin));
91      }
92  }