001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.beanutils.bugs;
018    
019    import junit.framework.Test;
020    import junit.framework.TestCase;
021    import junit.framework.TestSuite;
022    
023    import org.apache.commons.beanutils.PropertyUtils;
024    import org.apache.commons.logging.Log;
025    import org.apache.commons.logging.LogFactory;
026    
027    /**
028     * See https://issues.apache.org/jira/browse/BEANUTILS-349
029     * <p />
030     *
031     * @version $Revision$ $Date$
032     */
033    public class Jira349TestCase extends TestCase {
034    
035        private Log log = LogFactory.getLog(Jira349TestCase .class);
036    
037        /**
038         * Create a test case with the specified name.
039         *
040         * @param name The name of the test
041         */
042        public Jira349TestCase(String name) {
043            super(name);
044        }
045    
046        /**
047         * Run the Test.
048         *
049         * @param args Arguments
050         */
051        public static void main(String[] args) {
052            junit.textui.TestRunner.run(suite());
053        }
054    
055        /**
056         * Create a test suite for this test.
057         *
058         * @return a test suite
059         */
060        public static Test suite() {
061            return (new TestSuite(Jira349TestCase.class));
062        }
063    
064        /**
065         * Set up.
066         *
067         * @throws java.lang.Exception
068         */
069        protected void setUp() throws Exception {
070            super.setUp();
071        }
072    
073        /**
074         * Tear Down.
075         *
076         * @throws java.lang.Exception
077         */
078        protected void tearDown() throws Exception {
079            super.tearDown();
080        }
081    
082        /**
083         * Test {@link PropertyUtils#copyProperties(Object, Object)}
084         */
085        public void testIssue_BEANUTILS_349_PropertyUtils_copyProperties() {
086            PrimitiveBean dest = new PrimitiveBean();
087            ObjectBean origin = new ObjectBean ();
088            try {
089                PropertyUtils.copyProperties(dest, origin);
090            } catch (NullPointerException e) {
091                log.error("Failed", e);
092                fail("Threw NullPointerException");
093            } catch (IllegalArgumentException e) {
094                log.warn("Expected Result", e);
095            } catch (Throwable t) {
096                log.error("Failed", t);
097                fail("Threw exception: " + t);
098            }
099        }
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    }