You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2016/09/14 09:46:32 UTC
svn commit: r1760667 - in
/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils:
IndexedPropertyTestCase.java bugs/Jira492TestCase.java
bugs/other/Jira492IndexedListsSupport.java
Author: stain
Date: Wed Sep 14 09:46:32 2016
New Revision: 1760667
URL: http://svn.apache.org/viewvc?rev=1760667&view=rev
Log:
BEANUTILS-492: Common supportsIndexedLists() method
Added:
commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/other/Jira492IndexedListsSupport.java
Modified:
commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/IndexedPropertyTestCase.java
commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/IndexedPropertyTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/IndexedPropertyTestCase.java?rev=1760667&r1=1760666&r2=1760667&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/IndexedPropertyTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/IndexedPropertyTestCase.java Wed Sep 14 09:46:32 2016
@@ -19,18 +19,15 @@ package org.apache.commons.beanutils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeTrue;
-import java.beans.BeanInfo;
import java.beans.IndexedPropertyDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.beanutils.bugs.other.Jira492IndexedListsSupport;
import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
@@ -130,10 +127,11 @@ public class IndexedPropertyTestCase {
public void testListIndexedPropertyDescriptor() throws Exception {
final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
assertNotNull("No List Descriptor", descriptor);
-// BEANUTILS-492 - can't assume lists are handled as arrays in Java 8+
-// assertEquals("Not IndexedPropertyDescriptor",
-// IndexedPropertyDescriptor.class,
-// descriptor.getClass());
+ if (Jira492IndexedListsSupport.supportsIndexedLists()) {
+ // BEANUTILS-492 - can't assume lists are handled as arrays in Java 8+
+ assertEquals("Not IndexedPropertyDescriptor",
+ IndexedPropertyDescriptor.class, descriptor.getClass());
+ }
assertEquals("PropertDescriptor Type invalid",
List.class,
descriptor.getPropertyType());
@@ -146,9 +144,10 @@ public class IndexedPropertyTestCase {
public void testArrayListIndexedPropertyDescriptor() throws Exception {
final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
assertNotNull("No ArrayList Descriptor", descriptor);
-// assertEquals("Not IndexedPropertyDescriptor",
-// IndexedPropertyDescriptor.class,
-// descriptor.getClass());
+ if (Jira492IndexedListsSupport.supportsIndexedLists()) {
+ assertEquals("Not IndexedPropertyDescriptor",
+ IndexedPropertyDescriptor.class, descriptor.getClass());
+ }
assertEquals("PropertDescriptor Type invalid",
ArrayList.class,
descriptor.getPropertyType());
@@ -222,18 +221,6 @@ public class IndexedPropertyTestCase {
assertNotNull("No List Write Method", descriptor.getWriteMethod());
}
- public static void assumeSupportsIndexedLists() throws IntrospectionException {
- BeanInfo beanInfo = Introspector.getBeanInfo(IndexedTestBean.class);
- for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
- if (pd.getName().equals("stringList")) {
- Assume.assumeTrue("BEANUTILS-492: IndexedPropertyDescriptor no longer supported for java.util.List",
- pd instanceof IndexedPropertyDescriptor);
- return;
- }
- }
- Assert.fail("Could not find PropertyDescriptor for 'stringList'");
- }
-
/**
* Test Indexed Read Method for a List
*/
@@ -241,7 +228,8 @@ public class IndexedPropertyTestCase {
public void testListIndexedReadMethod() throws Exception {
final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
assertNotNull("stringList descriptor not found", descriptor);
- assumeSupportsIndexedLists();
+ assumeTrue("JDK does not support index bean properties on java.util.List",
+ Jira492IndexedListsSupport.supportsIndexedLists());
assertNotNull("No List Indexed Read Method", ((IndexedPropertyDescriptor)descriptor).getIndexedReadMethod());
}
@@ -252,7 +240,8 @@ public class IndexedPropertyTestCase {
public void testListIndexedWriteMethod() throws Exception {
final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
assertNotNull("stringList descriptor not found", descriptor);
- assumeSupportsIndexedLists();
+ assumeTrue("JDK does not support index bean properties on java.util.List",
+ Jira492IndexedListsSupport.supportsIndexedLists());
assertNotNull("No List Indexed Write Method", ((IndexedPropertyDescriptor)descriptor).getIndexedWriteMethod());
}
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java?rev=1760667&r1=1760666&r2=1760667&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java Wed Sep 14 09:46:32 2016
@@ -16,22 +16,19 @@
*/
package org.apache.commons.beanutils.bugs;
+import static org.apache.commons.beanutils.bugs.other.Jira492IndexedListsSupport.supportsIndexedLists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.beans.BeanInfo;
import java.beans.IndexedPropertyDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
import java.beans.PropertyDescriptor;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;
-import org.junit.Assert;
+import org.apache.commons.beanutils.bugs.other.Jira492IndexedListsSupport.IndexedBean;
import org.junit.Before;
import org.junit.Test;
@@ -41,6 +38,7 @@ import org.junit.Test;
* returned for properties of type {@link List}, they
* can still be accessed as positional items.
*
+ * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
*/
public class Jira492TestCase {
@@ -48,34 +46,6 @@ public class Jira492TestCase {
private final PropertyUtilsBean propertyUtils = new PropertyUtilsBean();
- public static class IndexedBean {
- private List<String> someList = new ArrayList<String>();
- public List<String> getSomeList() {
- return someList;
- }
- public void setSomeList(List<String> someList) {
- this.someList = someList;
- }
- public void setSomeList(int i, String value) {
- someList.set(i, value);
- }
- public String getSomeList(int i) {
- return someList.get(i);
- }
- }
-
- public static boolean supportsIndexedLists() throws IntrospectionException {
- BeanInfo beanInfo = Introspector.getBeanInfo(IndexedBean.class);
- for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
- if (pd.getName().equals("someList")) {
- return pd instanceof IndexedPropertyDescriptor;
- }
- }
- Assert.fail("Could not find PropertyDescriptor for 'file'");
- return false;
- }
-
-
private IndexedBean bean;
@Before
@@ -144,8 +114,6 @@ public class Jira492TestCase {
// Java 7 or earlier? (BEANUTILS-492)
IndexedPropertyDescriptor indexed = (IndexedPropertyDescriptor) propDesc;
assertEquals(String.class, indexed.getIndexedReadMethod().getReturnType());
- } else {
-
}
}
Added: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/other/Jira492IndexedListsSupport.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/other/Jira492IndexedListsSupport.java?rev=1760667&view=auto
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/other/Jira492IndexedListsSupport.java (added)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/other/Jira492IndexedListsSupport.java Wed Sep 14 09:46:32 2016
@@ -0,0 +1,61 @@
+/*
+ * 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.beanutils.bugs.other;
+
+import java.beans.BeanInfo;
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test if BeanInfo supports index properties for java.util.List
+ * <p>
+ * This was supported by Java until Java 8 (BEANUTILS-492).
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
+ */
+public class Jira492IndexedListsSupport {
+ public static class IndexedBean {
+ private List<String> someList = new ArrayList<String>();
+ public List<String> getSomeList() {
+ return someList;
+ }
+ public void setSomeList(List<String> someList) {
+ this.someList = someList;
+ }
+ public void setSomeList(int i, String value) {
+ someList.set(i, value);
+ }
+ public String getSomeList(int i) {
+ return someList.get(i);
+ }
+ }
+
+ public static boolean supportsIndexedLists() throws IntrospectionException {
+ BeanInfo beanInfo = Introspector.getBeanInfo(IndexedBean.class);
+ for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+ if (pd.getName().equals("someList")) {
+ return pd instanceof IndexedPropertyDescriptor;
+ }
+ }
+ throw new IllegalStateException("Could not find PropertyDescriptor for 'file'");
+ }
+
+}