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.bugs;
18  
19  import junit.framework.Test;
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  import org.apache.commons.beanutils.PropertyUtils;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /**
28   * @version $Id$
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 Jira349TestCase extends TestCase {
32  
33      private final Log log = LogFactory.getLog(Jira349TestCase .class);
34  
35      /**
36       * Create a test case with the specified name.
37       *
38       * @param name The name of the test
39       */
40      public Jira349TestCase(final String name) {
41          super(name);
42      }
43  
44      /**
45       * Run the Test.
46       *
47       * @param args Arguments
48       */
49      public static void main(final String[] args) {
50          junit.textui.TestRunner.run(suite());
51      }
52  
53      /**
54       * Create a test suite for this test.
55       *
56       * @return a test suite
57       */
58      public static Test suite() {
59          return (new TestSuite(Jira349TestCase.class));
60      }
61  
62      /**
63       * Set up.
64       *
65       * @throws java.lang.Exception
66       */
67      @Override
68      protected void setUp() throws Exception {
69          super.setUp();
70      }
71  
72      /**
73       * Tear Down.
74       *
75       * @throws java.lang.Exception
76       */
77      @Override
78      protected void tearDown() throws Exception {
79          super.tearDown();
80      }
81  
82      /**
83       * Test {@link PropertyUtils#copyProperties(Object, Object)}
84       */
85      public void testIssue_BEANUTILS_349_PropertyUtils_copyProperties() {
86          final PrimitiveBean dest = new PrimitiveBean();
87          final ObjectBean origin = new ObjectBean ();
88          try {
89              PropertyUtils.copyProperties(dest, origin);
90          } catch (final NullPointerException e) {
91              log.error("Failed", e);
92              fail("Threw NullPointerException");
93          } catch (final IllegalArgumentException e) {
94              log.warn("Expected Result", e);
95          } catch (final Throwable t) {
96              log.error("Failed", t);
97              fail("Threw exception: " + t);
98          }
99      }
100 
101     /**
102      * Test Bean with a primitive boolean property.
103      */
104     public static class PrimitiveBean {
105         private boolean testProperty;
106         public boolean getTestProperty() {
107             return testProperty;
108         }
109         public void setTestProperty(final boolean testProperty) {
110             this.testProperty = testProperty;
111         }
112     }
113 
114     /**
115      * Test Bean with a Boolean object property.
116      */
117     public static class ObjectBean {
118         private Boolean testProperty;
119         public Boolean getTestProperty() {
120             return testProperty;
121         }
122         public void setTestProperty(final Boolean testProperty) {
123             this.testProperty = testProperty;
124         }
125     }
126 }