This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push: new 3a4c9f2c Pull up the "2" classes's method into their respective supertype and adjust the tests to make the "2" behavior the _only_ behavior 3a4c9f2c is described below commit 3a4c9f2c8edbe4a438f7c909bdf6b31615e92250 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Sep 2 16:17:21 2024 -0400 Pull up the "2" classes's method into their respective supertype and adjust the tests to make the "2" behavior the _only_ behavior - As discussed on the mailing list - Better Javadoc are a TODO - Remove the "2" classes --- pom.xml | 2 +- src/changes/changes.xml | 19 ++- .../apache/commons/beanutils2/BeanUtilsBean.java | 55 ++++++-- .../apache/commons/beanutils2/BeanUtilsBean2.java | 75 ---------- .../commons/beanutils2/ConvertUtilsBean.java | 93 ++++--------- .../commons/beanutils2/ConvertUtilsBean2.java | 77 ----------- .../commons/beanutils2/BeanUtilsBean2TestCase.java | 154 --------------------- .../commons/beanutils2/BeanUtilsBeanTestCase.java | 19 +-- .../commons/beanutils2/ConvertUtilsTestCase.java | 46 +++--- .../commons/beanutils2/bugs/Jira520TestCase.java | 2 +- 10 files changed, 119 insertions(+), 423 deletions(-) diff --git a/pom.xml b/pom.xml index 4f05563d..9e1fb168 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ <commons.jacoco.classRatio>0.95</commons.jacoco.classRatio> <commons.jacoco.instructionRatio>0.69</commons.jacoco.instructionRatio> <!-- methodRatio is 0.76 on Java 8, and 0.77 on Java 11 and up. --> - <commons.jacoco.methodRatio>0.75</commons.jacoco.methodRatio> + <commons.jacoco.methodRatio>0.74</commons.jacoco.methodRatio> <commons.jacoco.branchRatio>0.67</commons.jacoco.branchRatio> <commons.jacoco.complexityRatio>0.61</commons.jacoco.complexityRatio> <commons.jacoco.lineRatio>0.72</commons.jacoco.lineRatio> diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bd322d30..b13f35df 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -29,15 +29,12 @@ </properties> <body> <release version="2.0.0" date="20YY-MM-DD" description="Update to Java 8."> - <action issue="BEANUTILS-346" dev="melloware" type="update" due-to="Melloware"> - New converter for Enum. - </action> - <action issue="BEANUTILS-402" dev="melloware" type="update" due-to="Melloware"> - Double-Checked Locking anti pattern in WeakFastHashMap. - </action> <action issue="BEANUTILS-503" dev="ggregory" type="update" due-to="Gary Gregory"> Change packaging from org.apache.commons.beanutils to org.apache.commons.beanutils2. </action> + <action issue="BEANUTILS-402" dev="melloware" type="fix" due-to="Melloware"> + Double-Checked Locking anti pattern in WeakFastHashMap. + </action> <action issue="BEANUTILS-505" dev="ggregory" type="update" due-to="Gary Gregory"> Add missing serialVersionUID to Serializable classes. </action> @@ -128,6 +125,7 @@ <action type="fix" dev="ggregory" due-to="Gary Gregory">Replace internal use of Locale.ENGLISH with Locale.ROOT.</action> <action issue="BEANUTILS-541" dev="ggregory" type="fix" due-to="Sergey Chernov">FluentPropertyBeanIntrospector caches corrupted writeMethod (2.x) #68.</action> <!-- ADD --> + <action issue="BEANUTILS-346" dev="melloware" type="add" due-to="Melloware">New converter for Enum.</action> <action dev="ggregory" type="add" due-to="Dependabot, Gary Gregory"> Add github/codeql-action #118. </action> @@ -213,6 +211,15 @@ <action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot"> Bump commons-logging:commons-logging from 1.2 to 1.3.4 #226, #246, #259, #275. </action> + <!-- REMOVE --> + <action dev="ggregory" type="update" due-to="Gary Gregory, Niall Pemberton"> + Removed BeanUtilsBean2, use BeanUtilsBean. BeanUtilsBean2 functionality is now in BeanUtilsBean. + Previous BeanUtilsBean functionality for those methods is no longer supported. + </action> + <action dev="ggregory" type="update" due-to="Gary Gregory, Niall Pemberton"> + Removed ConvertUtilsBean2, use ConvertUtilsBean. ConvertUtilsBean2 functionality is now in ConvertUtilsBean. + Previous ConvertUtilsBean functionality for those methods is no longer supported. + </action> </release> <release version="1.9.4" date="2019-08-13" description="The primary reason for this release is a bugfix for diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java index bbd6ded2..fc733179 100644 --- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java @@ -32,6 +32,42 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** + * TODO docs + * + * <p>2.0</p> + * + * <p>{@link BeanUtilsBean} implementation that creates a + * {@link ConvertUtilsBean} and delegates conversion to + * {@link ConvertUtilsBean#convert(Object, Class)}. + * </p> + * + * <p> + * To configure this implementation for the current context ClassLoader invoke + * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} + * </p> + * + * <p> + * BeanUtils 1.7.0 delegated all conversion to String to the converter + * registered for the {@code String.class}. One of the improvements in + * BeanUtils 1.8.0 was to upgrade the {@link Converter} implementations so + * that they could handle conversion to String for their type (e.g. + * IntegerConverter now handles conversion from an Integer to a String as + * well as String to Integer). + * </p> + * + * <p> + * In order to take advantage of these improvements BeanUtils needs to change + * how it gets the appropriate {@link Converter}. This functionality has been + * implemented in the new {@link ConvertUtilsBean#lookup(Class, Class)} and + * {@link ConvertUtilsBean#convert(Object, Class)} methods. However changing + * {@link BeanUtilsBean} to use these methods could create compatibility + * issues for existing users. In order to avoid that, this new + * {@link BeanUtilsBean} implementation has been created (and the associated + * {@link ConvertUtilsBean}). + * </p> + * + * <p>Pre-2.0</p> + * * <p>JavaBean property population methods.</p> * * <p>This class provides implementations for the utility methods in @@ -117,13 +153,13 @@ public class BeanUtilsBean { * <p>Constructs an instance using given conversion instances * and new {@link PropertyUtilsBean} instance.</p> * - * @param convertUtilsBean use this {@code ConvertUtilsBean} + * @param todoRemove use this {@code ConvertUtilsBean} * to perform conversions from one object to another * * @since 1.8.0 */ - public BeanUtilsBean(final ConvertUtilsBean convertUtilsBean) { - this(convertUtilsBean, new PropertyUtilsBean()); + public BeanUtilsBean(final ConvertUtilsBean todoRemove) { + this(new ConvertUtilsBean(), new PropertyUtilsBean()); } /** @@ -182,23 +218,12 @@ public class BeanUtilsBean { * <p>Converts the value to an object of the specified class (if * possible).</p> * - * @param <R> The desired return type * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - * @since 1.8.0 */ protected <R> Object convert(final Object value, final Class<R> type) { - final Converter<R> converter = getConvertUtils().lookup(type); - if (converter != null) { - if (LOG.isTraceEnabled()) { - LOG.trace(" USING CONVERTER " + converter); - } - return converter.convert(type, value); - } - return value; + return getConvertUtils().convert(value, type); } /** diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java deleted file mode 100644 index bf6ba35e..00000000 --- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -/** - * <p>{@link BeanUtilsBean} implementation that creates a - * {@link ConvertUtilsBean2} and delegates conversion to - * {@link ConvertUtilsBean#convert(Object, Class)}. - * </p> - * - * <p> - * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - * </p> - * - * <p> - * BeanUtils 1.7.0 delegated all conversion to String to the converter - * registered for the {@code String.class}. One of the improvements in - * BeanUtils 1.8.0 was to upgrade the {@link Converter} implementations so - * that they could handle conversion to String for their type (e.g. - * IntegerConverter now handles conversion from an Integer to a String as - * well as String to Integer). - * </p> - * - * <p> - * In order to take advantage of these improvements BeanUtils needs to change - * how it gets the appropriate {@link Converter}. This functionality has been - * implemented in the new {@link ConvertUtilsBean#lookup(Class, Class)} and - * {@link ConvertUtilsBean#convert(Object, Class)} methods. However changing - * {@link BeanUtilsBean} to use these methods could create compatibility - * issues for existing users. In order to avoid that, this new - * {@link BeanUtilsBean} implementation has been created (and the associated - * {@link ConvertUtilsBean2}). - * </p> - * - * @see ConvertUtilsBean2 - * @since 1.8.0 - */ -public class BeanUtilsBean2 extends BeanUtilsBean { - - /** - * <p>Constructs an instance using new property - * and conversion instances.</p> - */ - public BeanUtilsBean2() { - super(new ConvertUtilsBean2()); - } - - /** - * <p>Converts the value to an object of the specified class (if - * possible).</p> - * - * @param value Value to be converted (may be null) - * @param type Class of the value to be converted to - * @return The converted value - */ - @Override - protected <R> Object convert(final Object value, final Class<R> type) { - return getConvertUtils().convert(value, type); - } -} diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java index 92ea2e85..5a569a72 100644 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java @@ -97,6 +97,19 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** + * TODO DOCS + * <p>2.0</p> + * + * {@link ConvertUtilsBean} implementation that delegates {@code convert()} + * methods to the new {@link ConvertUtilsBean#convert(Object, Class)} method. + * + * <p> + * To configure this implementation for the current context ClassLoader invoke + * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} + * </p> + * + * <p>Pre-2.0</p> + * * <p>Utility methods for converting String scalar values to objects of the * specified Class, String arrays to arrays of the specified Class. The * actual {@link Converter} instance to be used can be registered for each @@ -220,35 +233,16 @@ public class ConvertUtilsBean { } /** - * Converts the specified value into a String. If the specified value - * is an array, the first element (converted to a String) will be - * returned. The registered {@link Converter} for the - * {@link String} class will be used, which allows - * applications to customize Object->String conversions (the default - * implementation simply uses toString()). + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null + * + * @see ConvertUtilsBean#convert(String[], Class) */ - public String convert(Object value) { - - if (value == null) { - return null; - } - if (!value.getClass().isArray()) { - final Converter<String> converter = lookup(String.class); - return converter.convert(String.class, value); - } - if (Array.getLength(value) < 1) { - return null; - } - value = Array.get(value, 0); - if (value == null) { - return null; - } - final Converter<String> converter = lookup(String.class); - return converter.convert(String.class, value); - + public String convert(final Object value) { + return (String) convert(value, String.class); } /** @@ -307,58 +301,31 @@ public class ConvertUtilsBean { } /** - * Converts the specified value to an object of the specified class (if - * possible). Otherwise, return a {@link String} representation of the value. + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * - * @param <T> The <em>desired</em> return type * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) - * @return The converted value + * @return The converted value or null if value is null * - * @throws ConversionException if thrown by an underlying Converter + * @see ConvertUtilsBean#convert(String[], Class) */ public <T> Object convert(final String value, final Class<T> clazz) { - if (LOG.isDebugEnabled()) { - LOG.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); - } - final Converter<T> converter = lookup(clazz); - if (converter == null) { - final Converter<String> sConverter = lookup(String.class); - if (LOG.isTraceEnabled()) { - LOG.trace(" Using converter " + converter); - } - return sConverter.convert(String.class, value); - } - if (LOG.isTraceEnabled()) { - LOG.trace(" Using converter " + converter); - } - return converter.convert(clazz, value); + return convert((Object) value, clazz); } /** - * Converts an array of specified values to an array of objects of the - * specified class (if possible). If the specified Java class is itself - * an array class, this class will be the type of the returned value. - * Otherwise, an array will be constructed whose component type is the - * specified class. + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * - * @param <T> The Class type. - * @param values Array of values to be converted + * @param value Array of values to be converted * @param clazz Java array or element class to be converted to (must not be null) * @return The converted value * - * @throws ConversionException if thrown by an underlying Converter + * @see ConvertUtilsBean#convert(String[], Class) */ - public <T> Object convert(final String[] values, final Class<T> clazz) { - final Class<?> type = clazz.isArray() ? clazz.getComponentType() : clazz; - if (LOG.isDebugEnabled()) { - LOG.debug("Convert String[" + values.length + "] to class '" + type.getName() + "[]'"); - } - Converter converter = lookup(type); - if (converter == null) { - converter = lookup(String.class); - } - return convert(values, type, converter); + public <T> Object convert(final String[] value, final Class<T> clazz) { + return convert((Object) value, clazz); } private <T> Object convert(final String[] values, final Class<T> type, final Converter<T> converter) { diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java deleted file mode 100644 index e268d49c..00000000 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -/** - * {@link ConvertUtilsBean} implementation that delegates {@code convert()} - * methods to the new {@link ConvertUtilsBean#convert(Object, Class)} method. - * - * <p> - * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - * </p> - * - * @see BeanUtilsBean2 - * @since 1.8.0 - */ -public class ConvertUtilsBean2 extends ConvertUtilsBean { - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @return The converted String value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public String convert(final Object value) { - return (String) convert(value, String.class); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @param clazz Java class to be converted to (must not be null) - * @return The converted value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public <T> Object convert(final String value, final Class<T> clazz) { - return convert((Object) value, clazz); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Array of values to be converted - * @param clazz Java array or element class to be converted to (must not be null) - * @return The converted value - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public <T> Object convert(final String[] value, final Class<T> clazz) { - return convert((Object) value, clazz); - } - -} diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java deleted file mode 100644 index 7c559b20..00000000 --- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Test Case for the {@link BeanUtilsBean2}. - */ -public class BeanUtilsBean2TestCase extends BeanUtilsBeanTestCase { - - /** - * Sets up instance variables required by this test case. - */ - @Override - @BeforeEach - public void setUp() { - ConvertUtils.deregister(); - BeanUtilsBean.setInstance(new BeanUtilsBean2()); - setUpShared(); - } - - /** - * Tear down instance variables required by this test case. - */ - @Override - @AfterEach - public void tearDown() { - bean = null; - } - - /** - * Test {@code copyProperty()} converting to a String. - */ - @Override - @Test - public void testCopyPropertyConvertToString() throws Exception { - BeanUtils.copyProperty(bean, "stringProperty", testUtilDate); - assertEquals(testStringDate, bean.getStringProperty(), "java.util.Date --> String"); - } - - /** - * Test {@code copyProperty()} converting to a String. - */ - @Override - @Test - public void testCopyPropertyConvertToStringArray() throws Exception { - bean.setStringArray(null); - BeanUtils.copyProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); - assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); - assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); - } - - /** - * Test {@code copyProperty()} converting to a String on indexed property - */ - @Override - @Test - public void testCopyPropertyConvertToStringIndexed() throws Exception { - bean.setStringArray(new String[1]); - BeanUtils.copyProperty(bean, "stringArray[0]", testUtilDate); - assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); - assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); - } - - /** - * Test {@code getArrayProperty()} converting to a String. - */ - @Override - @Test - public void testGetArrayPropertyDate() throws Exception { - String[] value = null; - bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); - value = BeanUtils.getArrayProperty(bean, "dateArrayProperty"); - assertEquals(1, value.length, "java.util.Date[] --> String[] length"); - assertEquals(testStringDate, value[0], "java.util.Date[] --> String[] value "); - } - - /** - * Test {@code getArrayProperty()} converting to a String. - */ - @Override - @Test - public void testGetIndexedPropertyDate() throws Exception { - String value = null; - bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); - value = BeanUtils.getIndexedProperty(bean, "dateArrayProperty[0]"); - assertEquals(testStringDate, value, "java.util.Date[0] --> String"); - } - - /** - * Test {@code getSimpleProperty()} converting to a String. - */ - @Override - @Test - public void testGetSimplePropertyDate() throws Exception { - String value = null; - bean.setDateProperty(testUtilDate); - value = BeanUtils.getSimpleProperty(bean, "dateProperty"); - assertEquals(testStringDate, value, "java.util.Date --> String"); - } - - /** - * Test {@code setProperty()} converting to a String. - */ - @Override - @Test - public void testSetPropertyConvertToString() throws Exception { - BeanUtils.setProperty(bean, "stringProperty", testUtilDate); - assertEquals(testStringDate, bean.getStringProperty(), "java.util.Date --> String"); - } - - /** - * Test {@code setProperty()} converting to a String array. - */ - @Override - @Test - public void testSetPropertyConvertToStringArray() throws Exception { - bean.setStringArray(null); - BeanUtils.setProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); - assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); - assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); - } - - /** - * Test {@code setProperty()} converting to a String on indexed property - */ - @Override - @Test - public void testSetPropertyConvertToStringIndexed() throws Exception { - bean.setStringArray(new String[1]); - BeanUtils.setProperty(bean, "stringArray[0]", testUtilDate); - assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date --> String[]"); - } - -} diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java index 97a314d4..41bfe098 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java @@ -371,7 +371,7 @@ public class BeanUtilsBeanTestCase { @Test public void testCopyPropertyConvertToString() throws Exception { BeanUtils.copyProperty(bean, "stringProperty", testUtilDate); - assertEquals(testUtilDate.toString(), bean.getStringProperty(), "java.util.Date --> String"); + assertEquals(testStringDate, bean.getStringProperty(), "java.util.Date --> String"); } /** @@ -382,7 +382,7 @@ public class BeanUtilsBeanTestCase { bean.setStringArray(null); BeanUtils.copyProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); - assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date[] --> String[] value "); + assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); } /** @@ -392,7 +392,8 @@ public class BeanUtilsBeanTestCase { public void testCopyPropertyConvertToStringIndexed() throws Exception { bean.setStringArray(new String[1]); BeanUtils.copyProperty(bean, "stringArray[0]", testUtilDate); - assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date --> String[]"); + assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); + assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); } /** @@ -684,7 +685,7 @@ public class BeanUtilsBeanTestCase { bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); value = BeanUtils.getArrayProperty(bean, "dateArrayProperty"); assertEquals(1, value.length, "java.util.Date[] --> String[] length"); - assertEquals(testUtilDate.toString(), value[0], "java.util.Date[] --> String[] value "); + assertEquals(testStringDate, value[0], "java.util.Date[] --> String[] value "); } /** @@ -736,7 +737,7 @@ public class BeanUtilsBeanTestCase { String value = null; bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); value = BeanUtils.getIndexedProperty(bean, "dateArrayProperty[0]"); - assertEquals(testUtilDate.toString(), value, "java.util.Date[0] --> String"); + assertEquals(testStringDate, value, "java.util.Date[0] --> String"); } @Test @@ -782,7 +783,7 @@ public class BeanUtilsBeanTestCase { String value = null; bean.setDateProperty(testUtilDate); value = BeanUtils.getSimpleProperty(bean, "dateProperty"); - assertEquals(testUtilDate.toString(), value, "java.util.Date --> String"); + assertEquals(testStringDate, value, "java.util.Date --> String"); } @Test @@ -1030,7 +1031,7 @@ public class BeanUtilsBeanTestCase { @Test public void testSetPropertyConvertToString() throws Exception { BeanUtils.setProperty(bean, "stringProperty", testUtilDate); - assertEquals(testUtilDate.toString(), bean.getStringProperty(), "java.util.Date --> String"); + assertEquals(testStringDate, bean.getStringProperty(), "java.util.Date --> String"); } /** @@ -1041,7 +1042,7 @@ public class BeanUtilsBeanTestCase { bean.setStringArray(null); BeanUtils.setProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); assertEquals(1, bean.getStringArray().length, "java.util.Date[] --> String[] length"); - assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date[] --> String[] value "); + assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date[] --> String[] value "); } /** @@ -1051,7 +1052,7 @@ public class BeanUtilsBeanTestCase { public void testSetPropertyConvertToStringIndexed() throws Exception { bean.setStringArray(new String[1]); BeanUtils.setProperty(bean, "stringArray[0]", testUtilDate); - assertEquals(testUtilDate.toString(), bean.getStringArray()[0], "java.util.Date --> String[]"); + assertEquals(testStringDate, bean.getStringArray()[0], "java.util.Date --> String[]"); } /** diff --git a/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java index dedbeb4f..5bbe6547 100644 --- a/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java @@ -299,24 +299,27 @@ public class ConvertUtilsTestCase { */ @Test public void testPositiveArray() { - + // check 1 final String[] values1 = { "10", "20", "30" }; - Object value = ConvertUtils.convert(values1, Integer.TYPE); final int[] shape = ArrayUtils.EMPTY_INT_ARRAY; + Object value = ConvertUtils.convert(values1, shape.getClass()); assertEquals(shape.getClass(), value.getClass()); final int[] results1 = (int[]) value; - assertEquals(results1[0], 10); - assertEquals(results1[1], 20); - assertEquals(results1[2], 30); - + assertEquals(10, results1[0]); + assertEquals(20, results1[1]); + assertEquals(30, results1[2]); + // check 2 final String[] values2 = { "100", "200", "300" }; value = ConvertUtils.convert(values2, shape.getClass()); assertEquals(shape.getClass(), value.getClass()); final int[] results2 = (int[]) value; - assertEquals(results2[0], 100); - assertEquals(results2[1], 200); - assertEquals(results2[2], 300); - + assertEquals(100, results2[0]); + assertEquals(200, results2[1]); + assertEquals(300, results2[2]); + // check 3 + value = ConvertUtils.convert(values1, Integer.TYPE); + assertEquals(Integer.class, value.getClass()); + assertEquals(Integer.valueOf(10), value); } /** @@ -324,35 +327,34 @@ public class ConvertUtilsTestCase { */ @Test public void testPositiveIntegerArray() { - Object value; final int[] intArray = {}; final int[] intArray1 = { 0 }; final int[] intArray2 = { 0, 10 }; - value = ConvertUtils.convert("{ }", intArray.getClass()); + final Class<? extends int[]> intArrayClass = intArray.getClass(); + value = ConvertUtils.convert("{ }", intArrayClass); checkIntegerArray(value, intArray); - value = ConvertUtils.convert("0", intArray.getClass()); + value = ConvertUtils.convert("0", intArrayClass); checkIntegerArray(value, intArray1); - value = ConvertUtils.convert(" 0 ", intArray.getClass()); + value = ConvertUtils.convert(" 0 ", intArrayClass); checkIntegerArray(value, intArray1); - value = ConvertUtils.convert("{ 0 }", intArray.getClass()); + value = ConvertUtils.convert("{ 0 }", intArrayClass); checkIntegerArray(value, intArray1); - value = ConvertUtils.convert("0,10", intArray.getClass()); + value = ConvertUtils.convert("0,10", intArrayClass); checkIntegerArray(value, intArray2); - value = ConvertUtils.convert("0 10", intArray.getClass()); + value = ConvertUtils.convert("0 10", intArrayClass); checkIntegerArray(value, intArray2); - value = ConvertUtils.convert("{0,10}", intArray.getClass()); + value = ConvertUtils.convert("{0,10}", intArrayClass); checkIntegerArray(value, intArray2); - value = ConvertUtils.convert("{0 10}", intArray.getClass()); + value = ConvertUtils.convert("{0 10}", intArrayClass); checkIntegerArray(value, intArray2); - value = ConvertUtils.convert("{ 0, 10 }", intArray.getClass()); + value = ConvertUtils.convert("{ 0, 10 }", intArrayClass); checkIntegerArray(value, intArray2); - value = ConvertUtils.convert("{ 0 10 }", intArray.getClass()); + value = ConvertUtils.convert("{ 0 10 }", intArrayClass); checkIntegerArray(value, intArray2); - } /** diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java index a1e8909b..188e7b01 100644 --- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java @@ -39,7 +39,7 @@ public class Jira520TestCase { bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); final AlphaBean bean = new AlphaBean(); final String result = bub.getProperty(bean, "class"); - assertEquals("class org.apache.commons.beanutils2.AlphaBean", result, "Class property should have been accessed"); + assertEquals("org.apache.commons.beanutils2.AlphaBean", result, "Class property should have been accessed"); } /**