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/12 15:49:49 UTC

svn commit: r1760395 - in /commons/proper/beanutils/trunk/src: main/java/org/apache/commons/beanutils/ test/java/org/apache/commons/beanutils/ test/java/org/apache/commons/beanutils/bugs/

Author: stain
Date: Mon Sep 12 15:49:49 2016
New Revision: 1760395

URL: http://svn.apache.org/viewvc?rev=1760395&view=rev
Log:
Code cleanup (no tabs!)

Modified:
    commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java
    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/Jira422TestCase.java
    commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422bTestCase.java
    commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira492TestCase.java

Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java?rev=1760395&r1=1760394&r2=1760395&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java Mon Sep 12 15:49:49 2016
@@ -895,7 +895,7 @@ public class PropertyUtilsBean {
      * for the last resolved property itself is returned.</p>
      *
      * <p><strong>FIXME</strong> - Does not work with DynaBeans.</p>
-     * 
+     *
      * <p>Note that for Java 8 and above, this method no longer return
      * IndexedPropertyDescriptor for {@link List}-typed properties, only for
      * properties typed as native array. (BEANUTILS-492).
@@ -1089,9 +1089,9 @@ public class PropertyUtilsBean {
      * <p>
      * If the property is an indexed property (e.g. <code>String[]</code>),
      * this method will return the type of the items within that array.
-     * Note that from Java 8 and newer, this method do not support  
+     * Note that from Java 8 and newer, this method do not support
      * such index types from items within an Collection, and will
-     * instead return the collection type (e.g. java.util.List) from the 
+     * instead return the collection type (e.g. java.util.List) from the
      * getter mtethod.
      *
      * @param bean Bean for which a property descriptor is requested

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=1760395&r1=1760394&r2=1760395&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 Mon Sep 12 15:49:49 2016
@@ -130,7 +130,7 @@ 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+
+// BEANUTILS-492 - can't assume lists are handled as arrays in Java 8+
 //            assertEquals("Not IndexedPropertyDescriptor",
 //                         IndexedPropertyDescriptor.class,
 //                         descriptor.getClass());
@@ -222,17 +222,17 @@ 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);
-			}					
-		}
-		Assert.fail("Could not find PropertyDescriptor for 'stringList'"); 
-	}
-	
+    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);
+            }
+        }
+        Assert.fail("Could not find PropertyDescriptor for 'stringList'");
+    }
+
     /**
      * Test Indexed Read Method for a List
      */
@@ -240,7 +240,7 @@ public class IndexedPropertyTestCase {
     public void testListIndexedReadMethod() throws Exception {
         final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
         assertNotNull("stringList descriptor not found", descriptor);
-        assumeSupportsIndexedLists();        
+        assumeSupportsIndexedLists();
         assertNotNull("No List Indexed Read Method",  ((IndexedPropertyDescriptor)descriptor).getIndexedReadMethod());
     }
 
@@ -248,10 +248,10 @@ public class IndexedPropertyTestCase {
      * Test Indexed Write Method for a List
      */
     @Test
-    public void testListIndexedWriteMethod() throws Exception {    	
+    public void testListIndexedWriteMethod() throws Exception {
         final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
         assertNotNull("stringList descriptor not found", descriptor);
-        assumeSupportsIndexedLists();		
+        assumeSupportsIndexedLists();
         assertNotNull("No List Indexed Write Method", ((IndexedPropertyDescriptor)descriptor).getIndexedWriteMethod());
     }
 

Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422TestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422TestCase.java?rev=1760395&r1=1760394&r2=1760395&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422TestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422TestCase.java Mon Sep 12 15:49:49 2016
@@ -35,42 +35,42 @@ import org.junit.Test;
 /**
  * getPropertyType return null on second descendant class
  * <p>
- * This test only work in Java 7 or earlier (See BEANUTILS-492) - as 
+ * This test only work in Java 7 or earlier (See BEANUTILS-492) - as
  * a weaker alternative, see {@link Jira422bTestCase}.
- * 
+ *
  *
  * @version $Id$
  * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-422">https://issues.apache.org/jira/browse/BEANUTILS-422</a>
  */
 public class Jira422TestCase {
 
-	/**
-	 * Detects BEANUTILS-492 in Java 8 or later
-	 * 
-	 * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
-	 */
-	@BeforeClass
-	public static void assumeSupportsIndexedLists() throws IntrospectionException {
-		BeanInfo beanInfo = Introspector.getBeanInfo(RootBean.class);
-		for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
-			if (pd.getName().equals("file")) {
-				Assume.assumeTrue("BEANUTILS-492: IndexedPropertyDescriptor no longer supported for java.util.List", 
-						pd instanceof IndexedPropertyDescriptor);
-			}					
-		}
-		Assert.fail("Could not find PropertyDescriptor for 'file'"); 
-	}
-	
-	@Test
-    public void testRootBean() throws Exception {    	
+    /**
+     * Detects BEANUTILS-492 in Java 8 or later
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
+     */
+    @BeforeClass
+    public static void assumeSupportsIndexedLists() throws IntrospectionException {
+        BeanInfo beanInfo = Introspector.getBeanInfo(RootBean.class);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (pd.getName().equals("file")) {
+                Assume.assumeTrue("BEANUTILS-492: IndexedPropertyDescriptor no longer supported for java.util.List",
+                        pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+        Assert.fail("Could not find PropertyDescriptor for 'file'");
+    }
+
+    @Test
+    public void testRootBean() throws Exception {
         final RootBean bean = new FirstChildBean();
         final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
         assertEquals(String.class.getName(), propertyType.getName());
     }
 
-	@Test	
-    public void testSecondChildBean() throws Exception {    	
-    	final RootBean bean = new SecondChildBean();
+    @Test
+    public void testSecondChildBean() throws Exception {
+        final RootBean bean = new SecondChildBean();
         final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
         assertEquals(String.class.getName(), propertyType.getName());
     }

Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422bTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422bTestCase.java?rev=1760395&r1=1760394&r2=1760395&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422bTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/bugs/Jira422bTestCase.java Mon Sep 12 15:49:49 2016
@@ -26,18 +26,18 @@ import org.junit.Test;
  *
  * @version $Id$
  * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-422">BEANUTILS-422</a>
- * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a> 
+ * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
  */
 public class Jira422bTestCase {
 
-    @Test	
+    @Test
     public void testRootBean() throws Exception {
         final RootBeanB bean = new FirstChildBeanB();
         final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
         assertEquals(String.class.getName(), propertyType.getName());
     }
 
-    
+
     @Test
     public void testSecondChildBean() throws Exception {
         final RootBeanB bean = new SecondChildBeanB();
@@ -74,4 +74,4 @@ class FirstChildBeanB extends RootBeanB
 }
 
 class SecondChildBeanB extends RootBeanB {
-}
\ No newline at end of file
+}

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=1760395&r1=1760394&r2=1760395&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 Mon Sep 12 15:49:49 2016
@@ -38,116 +38,116 @@ import org.junit.Test;
 /**
  * This test verifies that although BEANUTILS-492
  * means {@link IndexedPropertyDescriptor}s are not
- * returned for properties of type {@link List}, they 
+ * returned for properties of type {@link List}, they
  * can still be accessed as positional items.
- * 
+ *
  */
 public class Jira492TestCase {
 
-	private final BeanUtilsBean beanUtils = new BeanUtilsBean();
-	
-	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
-	public void makeBean() { 
-		bean = new IndexedBean();
-		bean.setSomeList(Arrays.asList("item0", "item1"));
-	}
-	
-	@Test
-	public void getIndexedProperty() throws Exception {
-		assertEquals("item0", beanUtils.getIndexedProperty(bean, "someList", 0));
-		assertEquals("item1", beanUtils.getIndexedProperty(bean, "someList[1]"));
-	}
-	
-	@Test
-	public void getPropertySubScript() throws Exception {
-		assertEquals("item0", beanUtils.getProperty(bean, "someList[0]"));
-		assertEquals("item1", beanUtils.getProperty(bean, "someList[1]"));
-	}		
-
-	@Test
-	public void setIndexedProperty() throws Exception {
-		beanUtils.setProperty(bean, "someList[1]", "item1-modified");
-		assertEquals("item1-modified", beanUtils.getIndexedProperty(bean, "someList", 1));				
-	}
-	
-	@Test
-	public void getProperty() throws Exception {
-		assertEquals("item0", beanUtils.getProperty(bean, "someList"));
-	}
-
-	@Test
-	public void getPropertyUnconverted() throws Exception {
-		Object someList = propertyUtils.getProperty(bean, "someList");
-		assertTrue("Did not retrieve list", someList instanceof List);		
-	}
-	
-	public void getArrayProperty() throws Exception {
-		String[] arr = beanUtils.getArrayProperty(bean, "someList");
-		assertEquals(2, arr.length);
-		assertEquals("item0", arr[0]);
-		assertEquals("item1", arr[1]);
-	}
-	
-	@Test
-	public void describe() throws Exception {
-		Map<String, String> described = beanUtils.describe(bean);
-		// Only first element survives as a String
-		assertEquals("item0", described.get("someList"));
-	}
-	
-	@Test
-	public void getPropertyType() throws Exception {
-		if (supportsIndexedLists()) {
-			// legacy behaviour (< Java 8)
-			assertEquals(String.class, propertyUtils.getPropertyType(bean, "someList[0]"));
-		} else {
-			assertEquals(List.class, propertyUtils.getPropertyType(bean, "someList"));
-		}		
-	}
-
-	@Test
-	public void getPropertyDescriptor() throws Exception {
-		PropertyDescriptor propDesc = propertyUtils.getPropertyDescriptor(bean, "someList");
-		if (supportsIndexedLists()) {
-			// Java 7 or earlier? (BEANUTILS-492)
-			IndexedPropertyDescriptor indexed = (IndexedPropertyDescriptor) propDesc;
-			assertEquals(String.class, indexed.getIndexedReadMethod().getReturnType());
-		} else {
-			
-		}
-	}
-	
-	
+    private final BeanUtilsBean beanUtils = new BeanUtilsBean();
+
+    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
+    public void makeBean() {
+        bean = new IndexedBean();
+        bean.setSomeList(Arrays.asList("item0", "item1"));
+    }
+
+    @Test
+    public void getIndexedProperty() throws Exception {
+        assertEquals("item0", beanUtils.getIndexedProperty(bean, "someList", 0));
+        assertEquals("item1", beanUtils.getIndexedProperty(bean, "someList[1]"));
+    }
+
+    @Test
+    public void getPropertySubScript() throws Exception {
+        assertEquals("item0", beanUtils.getProperty(bean, "someList[0]"));
+        assertEquals("item1", beanUtils.getProperty(bean, "someList[1]"));
+    }
+
+    @Test
+    public void setIndexedProperty() throws Exception {
+        beanUtils.setProperty(bean, "someList[1]", "item1-modified");
+        assertEquals("item1-modified", beanUtils.getIndexedProperty(bean, "someList", 1));
+    }
+
+    @Test
+    public void getProperty() throws Exception {
+        assertEquals("item0", beanUtils.getProperty(bean, "someList"));
+    }
+
+    @Test
+    public void getPropertyUnconverted() throws Exception {
+        Object someList = propertyUtils.getProperty(bean, "someList");
+        assertTrue("Did not retrieve list", someList instanceof List);
+    }
+
+    public void getArrayProperty() throws Exception {
+        String[] arr = beanUtils.getArrayProperty(bean, "someList");
+        assertEquals(2, arr.length);
+        assertEquals("item0", arr[0]);
+        assertEquals("item1", arr[1]);
+    }
+
+    @Test
+    public void describe() throws Exception {
+        Map<String, String> described = beanUtils.describe(bean);
+        // Only first element survives as a String
+        assertEquals("item0", described.get("someList"));
+    }
+
+    @Test
+    public void getPropertyType() throws Exception {
+        if (supportsIndexedLists()) {
+            // legacy behaviour (< Java 8)
+            assertEquals(String.class, propertyUtils.getPropertyType(bean, "someList[0]"));
+        } else {
+            assertEquals(List.class, propertyUtils.getPropertyType(bean, "someList"));
+        }
+    }
+
+    @Test
+    public void getPropertyDescriptor() throws Exception {
+        PropertyDescriptor propDesc = propertyUtils.getPropertyDescriptor(bean, "someList");
+        if (supportsIndexedLists()) {
+            // Java 7 or earlier? (BEANUTILS-492)
+            IndexedPropertyDescriptor indexed = (IndexedPropertyDescriptor) propDesc;
+            assertEquals(String.class, indexed.getIndexedReadMethod().getReturnType());
+        } else {
+
+        }
+    }
+
+
 }