You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2002/10/25 02:27:42 UTC
cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils DynaPropertyUtilsTestCase.java BeanComparatorTestCase.java BasicDynaBeanTestCase.java
dion 2002/10/24 17:27:42
Modified: beanutils/src/test/org/apache/commons/beanutils
DynaPropertyUtilsTestCase.java
BeanComparatorTestCase.java
BasicDynaBeanTestCase.java
Log:
Removed unused code.
All tests pass using maven test
Revision Changes Path
1.9 +6 -11 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java
Index: DynaPropertyUtilsTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DynaPropertyUtilsTestCase.java 21 Jul 2002 00:20:45 -0000 1.8
+++ DynaPropertyUtilsTestCase.java 25 Oct 2002 00:27:42 -0000 1.9
@@ -156,7 +156,6 @@
bean.set("booleanProperty", new Boolean(true));
bean.set("booleanSecond", new Boolean(true));
bean.set("doubleProperty", new Double(321.0));
- String dupProperty[] = { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4" };
bean.set("floatProperty", new Float((float) 123.0));
int intArray[] = { 0, 10, 20, 30, 40 };
bean.set("intArray", intArray);
@@ -1202,9 +1201,7 @@
public void testGetNestedUnknown() {
try {
- Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.unknown");
+ PropertyUtils.getNestedProperty(bean, "nested.unknown");
fail("Should have thrown NoSuchMethodException");
} catch (IllegalAccessException e) {
fail("IllegalAccessException");
@@ -1487,9 +1484,7 @@
public void testGetSimpleUnknown() {
try {
- Object value =
- PropertyUtils.getSimpleProperty(bean,
- "unknown");
+ PropertyUtils.getSimpleProperty(bean, "unknown");
fail("Should have thrown NoSuchMethodException");
} catch (IllegalAccessException e) {
fail("IllegalAccessException");
1.2 +306 -306 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanComparatorTestCase.java
Index: BeanComparatorTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanComparatorTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanComparatorTestCase.java 18 Oct 2002 17:41:48 -0000 1.1
+++ BeanComparatorTestCase.java 25 Oct 2002 00:27:42 -0000 1.2
@@ -1,306 +1,306 @@
-/*
- * $Header$
- * $Revision$
- * $Date$
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Commons", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.beanutils;
-
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Map;
-import junit.framework.TestCase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-
-/**
- * <p>
- * Test Case for the BeanComparator class.
- *
- * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
- * @version $Revision$
- */
-
-public class BeanComparatorTestCase extends TestCase {
-
- // ---------------------------------------------------- Instance Variables
-
- /**
- * The test beans for each test.
- */
- protected TestBean bean = null;
- protected AlphaBean alphaBean1 = null;
- protected AlphaBean alphaBean2 = null;
-
- // The test BeanComparator
- protected BeanComparator beanComparator = null;
-
-
-
-
-
- // ---------------------------------------------------------- Constructors
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanComparatorTestCase(String name) {
- super(name);
- }
-
-
- // -------------------------------------------------- Overall Test Methods
-
-
- /**
- * Set up instance variables required by this test case.
- */
- public void setUp() {
- bean = new TestBean();
- alphaBean1 = new AlphaBean("alphaBean1");
- alphaBean2 = new AlphaBean("alphaBean2");
-
-
- }
-
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return (new TestSuite(BeanComparatorTestCase.class));
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- public void tearDown() {
- bean = null;
- alphaBean1 = null;
- alphaBean2 = null;
- beanComparator = null;
- }
-
-
- // ------------------------------------------------ Individual Test Methods
-
-
- /**
- * tests comparing two beans via their name using the default Comparator
- */
- public void testSimpleCompare() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
- }
-
- /**
- * tests comparing two beans via their name using the default Comparator, but the inverse
- */
- public void testSimpleCompareInverse() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean2, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,result==1);
-
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
- }
-
- /**
- * tests comparing two beans via their name using the default Comparator where they have the same value.
- */
- public void testCompareIdentical() {
- try {
- alphaBean1 = new AlphaBean("alphabean");
- alphaBean2 = new AlphaBean("alphabean");
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,result==0);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
- }
-
- /**
- * tests comparing one bean against itself.
- */
- public void testCompareBeanAgainstSelf() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean1, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,result==0);
-
- }
- catch (Exception e) {
- fail("Exception");
- }
- }
-
- /**
- * tests comparing two beans via their name using the default Comparator, but with one of the beans
- * being null.
- */
- public void testCompareWithNulls() {
- try {
- beanComparator = new BeanComparator("name");
- int result = beanComparator.compare(alphaBean2, null);
-
- // DEP not sure if this is the best way to test an exception?
- fail("Should not be able to compare a null value.");
-
- }
- catch (Exception e) {
-
- }
- }
-
- /**
- * tests comparing two beans who don't have a property
- */
- public void testCompareOnMissingProperty() {
- try {
- beanComparator = new BeanComparator("bogusName");
- int result = beanComparator.compare(alphaBean2, alphaBean1);
- fail("should not be able to compare");
-
-
- }
- catch (ClassCastException cce){
- assertTrue("Wrong exception was thrown.",cce.toString().indexOf("Unknown property") > -1);
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
- }
-
- /**
- * tests comparing two beans on a boolean property, which is not possible.
- */
- public void testCompareOnBooleanProperty() {
- try {
- TestBean testBeanA = new TestBean();
- TestBean testBeanB = new TestBean();
-
- testBeanA.setBooleanProperty(true);
- testBeanB.setBooleanProperty(false);
-
- beanComparator = new BeanComparator("booleanProperty");
- int result = beanComparator.compare(testBeanA, testBeanB);
-
- fail("BeanComparator should throw an exception when comparing two booleans.");
-
- }
- catch (ClassCastException cce){
- assertTrue("Two booleans should not be comparable",cce.toString().indexOf("Both arguments of this method were not Comparables: java.lang.Boolean and java.lang.Boolean") >=0);
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
- }
-
- /**
- * tests comparing two beans on a boolean property, then changing the property and testing
- */
- public void testSetProperty() {
- try {
- TestBean testBeanA = new TestBean();
- TestBean testBeanB = new TestBean();
-
- testBeanA.setDoubleProperty(5.5);
- testBeanB.setDoubleProperty(1.0);
-
- beanComparator = new BeanComparator("doubleProperty");
- int result = beanComparator.compare(testBeanA, testBeanB);
-
- assertTrue("Comparator did not sort properly. Result:" + result,result==1);
-
- testBeanA.setStringProperty("string 1");
- testBeanB.setStringProperty("string 2");
-
- beanComparator.setProperty("stringProperty");
-
- result = beanComparator.compare(testBeanA, testBeanB);
-
- assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
-
- }
- catch (ClassCastException cce){
- fail("ClassCaseException " + cce.toString());
- }
- catch (Exception e) {
- fail("Exception" + e);
- }
- }
-}
-
-
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.beanutils;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * <p>
+ * Test Case for the BeanComparator class.
+ *
+ * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
+ * @version $Revision$
+ */
+
+public class BeanComparatorTestCase extends TestCase {
+
+ // ---------------------------------------------------- Instance Variables
+
+ /**
+ * The test beans for each test.
+ */
+ protected TestBean bean = null;
+ protected AlphaBean alphaBean1 = null;
+ protected AlphaBean alphaBean2 = null;
+
+ // The test BeanComparator
+ protected BeanComparator beanComparator = null;
+
+
+
+
+
+ // ---------------------------------------------------------- Constructors
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public BeanComparatorTestCase(String name) {
+ super(name);
+ }
+
+
+ // -------------------------------------------------- Overall Test Methods
+
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ bean = new TestBean();
+ alphaBean1 = new AlphaBean("alphaBean1");
+ alphaBean2 = new AlphaBean("alphaBean2");
+
+
+ }
+
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(BeanComparatorTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ bean = null;
+ alphaBean1 = null;
+ alphaBean2 = null;
+ beanComparator = null;
+ }
+
+
+ // ------------------------------------------------ Individual Test Methods
+
+
+ /**
+ * tests comparing two beans via their name using the default Comparator
+ */
+ public void testSimpleCompare() {
+ try {
+ beanComparator = new BeanComparator("name");
+ int result = beanComparator.compare(alphaBean1, alphaBean2);
+ assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
+
+ }
+ catch (Exception e) {
+ fail("Exception");
+ }
+ }
+
+ /**
+ * tests comparing two beans via their name using the default Comparator, but the inverse
+ */
+ public void testSimpleCompareInverse() {
+ try {
+ beanComparator = new BeanComparator("name");
+ int result = beanComparator.compare(alphaBean2, alphaBean1);
+ assertTrue("Comparator did not sort properly. Result:" + result,result==1);
+
+ }
+ catch (Exception e) {
+ fail("Exception" + e);
+ }
+ }
+
+ /**
+ * tests comparing two beans via their name using the default Comparator where they have the same value.
+ */
+ public void testCompareIdentical() {
+ try {
+ alphaBean1 = new AlphaBean("alphabean");
+ alphaBean2 = new AlphaBean("alphabean");
+ beanComparator = new BeanComparator("name");
+ int result = beanComparator.compare(alphaBean1, alphaBean2);
+ assertTrue("Comparator did not sort properly. Result:" + result,result==0);
+
+ }
+ catch (Exception e) {
+ fail("Exception");
+ }
+ }
+
+ /**
+ * tests comparing one bean against itself.
+ */
+ public void testCompareBeanAgainstSelf() {
+ try {
+ beanComparator = new BeanComparator("name");
+ int result = beanComparator.compare(alphaBean1, alphaBean1);
+ assertTrue("Comparator did not sort properly. Result:" + result,result==0);
+
+ }
+ catch (Exception e) {
+ fail("Exception");
+ }
+ }
+
+ /**
+ * tests comparing two beans via their name using the default Comparator, but with one of the beans
+ * being null.
+ */
+ public void testCompareWithNulls() {
+ try {
+ beanComparator = new BeanComparator("name");
+ beanComparator.compare(alphaBean2, null);
+
+ // DEP not sure if this is the best way to test an exception?
+ fail("Should not be able to compare a null value.");
+
+ }
+ catch (Exception e) {
+
+ }
+ }
+
+ /**
+ * tests comparing two beans who don't have a property
+ */
+ public void testCompareOnMissingProperty() {
+ try {
+ beanComparator = new BeanComparator("bogusName");
+ beanComparator.compare(alphaBean2, alphaBean1);
+ fail("should not be able to compare");
+
+
+ }
+ catch (ClassCastException cce){
+ assertTrue("Wrong exception was thrown.",cce.toString().indexOf("Unknown property") > -1);
+ }
+ catch (Exception e) {
+ fail("Exception" + e);
+ }
+ }
+
+ /**
+ * tests comparing two beans on a boolean property, which is not possible.
+ */
+ public void testCompareOnBooleanProperty() {
+ try {
+ TestBean testBeanA = new TestBean();
+ TestBean testBeanB = new TestBean();
+
+ testBeanA.setBooleanProperty(true);
+ testBeanB.setBooleanProperty(false);
+
+ beanComparator = new BeanComparator("booleanProperty");
+ beanComparator.compare(testBeanA, testBeanB);
+
+ fail("BeanComparator should throw an exception when comparing two booleans.");
+
+ }
+ catch (ClassCastException cce){
+ assertTrue("Two booleans should not be comparable",cce.toString().indexOf("Both arguments of this method were not Comparables: java.lang.Boolean and java.lang.Boolean") >=0);
+ }
+ catch (Exception e) {
+ fail("Exception" + e);
+ }
+ }
+
+ /**
+ * tests comparing two beans on a boolean property, then changing the property and testing
+ */
+ public void testSetProperty() {
+ try {
+ TestBean testBeanA = new TestBean();
+ TestBean testBeanB = new TestBean();
+
+ testBeanA.setDoubleProperty(5.5);
+ testBeanB.setDoubleProperty(1.0);
+
+ beanComparator = new BeanComparator("doubleProperty");
+ int result = beanComparator.compare(testBeanA, testBeanB);
+
+ assertTrue("Comparator did not sort properly. Result:" + result,result==1);
+
+ testBeanA.setStringProperty("string 1");
+ testBeanB.setStringProperty("string 2");
+
+ beanComparator.setProperty("stringProperty");
+
+ result = beanComparator.compare(testBeanA, testBeanB);
+
+ assertTrue("Comparator did not sort properly. Result:" + result,result==-1);
+
+ }
+ catch (ClassCastException cce){
+ fail("ClassCaseException " + cce.toString());
+ }
+ catch (Exception e) {
+ fail("Exception" + e);
+ }
+ }
+}
+
+
1.6 +4 -6 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BasicDynaBeanTestCase.java
Index: BasicDynaBeanTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BasicDynaBeanTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BasicDynaBeanTestCase.java 23 Jan 2002 22:52:26 -0000 1.5
+++ BasicDynaBeanTestCase.java 25 Oct 2002 00:27:42 -0000 1.6
@@ -773,8 +773,6 @@
*/
public void testSetMappedValues() {
- Object value = null;
-
try {
bean.set("mappedProperty", "First Key", "New First Value");
assertEquals("Can replace old value",
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>