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 * See https://issues.apache.org/jira/browse/BEANUTILS-349
29 * <p />
30 *
31 * @version $Revision$ $Date$
32 */
33 public class Jira349TestCase extends TestCase {
34
35 private Log log = LogFactory.getLog(Jira349TestCase .class);
36
37 /**
38 * Create a test case with the specified name.
39 *
40 * @param name The name of the test
41 */
42 public Jira349TestCase(String name) {
43 super(name);
44 }
45
46 /**
47 * Run the Test.
48 *
49 * @param args Arguments
50 */
51 public static void main(String[] args) {
52 junit.textui.TestRunner.run(suite());
53 }
54
55 /**
56 * Create a test suite for this test.
57 *
58 * @return a test suite
59 */
60 public static Test suite() {
61 return (new TestSuite(Jira349TestCase.class));
62 }
63
64 /**
65 * Set up.
66 *
67 * @throws java.lang.Exception
68 */
69 protected void setUp() throws Exception {
70 super.setUp();
71 }
72
73 /**
74 * Tear Down.
75 *
76 * @throws java.lang.Exception
77 */
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 PrimitiveBean dest = new PrimitiveBean();
87 ObjectBean origin = new ObjectBean ();
88 try {
89 PropertyUtils.copyProperties(dest, origin);
90 } catch (NullPointerException e) {
91 log.error("Failed", e);
92 fail("Threw NullPointerException");
93 } catch (IllegalArgumentException e) {
94 log.warn("Expected Result", e);
95 } catch (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(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(Boolean testProperty) {
123 this.testProperty = testProperty;
124 }
125 }
126 }