commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1237703 - in /commons/sandbox/beanutils2/trunk/src: changes/changes.xml main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
Date Mon, 30 Jan 2012 15:10:20 GMT
Author: simonetripodi
Date: Mon Jan 30 15:10:20 2012
New Revision: 1237703

URL: http://svn.apache.org/viewvc?rev=1237703&view=rev
Log:
[SANDBOX-371] Make sure that a property is readable in DefaultBeanAccessor.getProperty( String
name ) - patch provided by Benedikt Ritter

Modified:
    commons/sandbox/beanutils2/trunk/src/changes/changes.xml
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java

Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1237703&r1=1237702&r2=1237703&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Mon Jan 30 15:10:20 2012
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="0.1" date="201?-??-??" description="First release.">
+    <action dev="simonetripodi" type="update" issue="SANDBOX-371" due-to="Benedikt Ritter">
+      Make sure that a property is readable in DefaultBeanAccessor.getProperty( String name
)
+    </action>
     <action dev="simonetripodi" type="update" issue="SANDBOX-365" due-to="Benedikt Ritter">
       Extend Assertions for checking null references in arrays
     </action>

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java?rev=1237703&r1=1237702&r2=1237703&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
Mon Jan 30 15:10:20 2012
@@ -17,6 +17,7 @@ package org.apache.commons.beanutils2;
  * limitations under the License.
  */
 
+import static java.lang.String.format;
 import static org.apache.commons.beanutils2.Assertions.checkNotNull;
 
 import java.beans.IntrospectionException;
@@ -47,8 +48,13 @@ final class DefaultBeanAccessor<B>
         propertyDescriptor = checkNotNull( propertyDescriptor, "Property '%s' does not exist
in bean of type %s",
                                            name, bean.getClass().getName() );
 
-        Object newBean = propertyDescriptor.getReadMethod().invoke( bean );
+        if ( propertyDescriptor.getReadMethod() == null )
+        {
+            throw new NoSuchMethodException( format( "Bean of type %s does not provide a
getter for property '%s'!",
+                                                     bean.getClass().getName(), name ) );
+        }
 
+        Object newBean = propertyDescriptor.getReadMethod().invoke( bean );
         return new DefaultBeanAccessor<Object>( newBean );
     }
 

Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java?rev=1237703&r1=1237702&r2=1237703&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
(original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/GetPropertyTestCase.java
Mon Jan 30 15:10:20 2012
@@ -21,6 +21,7 @@ import static org.apache.commons.beanuti
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -35,7 +36,7 @@ public final class GetPropertyTestCase
         bean = new TestBean();
     }
 
-    @Before
+    @After
     public void tearDown()
     {
         bean = null;
@@ -49,9 +50,16 @@ public final class GetPropertyTestCase
         throws Exception
     {
         Object value = on( bean ).getProperty( "booleanProperty" ).get();
-        assertNotNull( "Got a value", value );
-        assertTrue( "Got correct type", ( value instanceof Boolean ) );
-        assertTrue( "Got correct value", ( (Boolean) value ).booleanValue() == bean.getBooleanProperty()
);
+        assertNotNull( "Got no value", value );
+        assertTrue( "Got a value of the wrong type", ( value instanceof Boolean ) );
+        assertTrue( "Got an incorrect value", ( (Boolean) value ).booleanValue() == bean.getBooleanProperty()
);
+    }
+
+    @Test( expected = NoSuchMethodException.class )
+    public void getWirteOnlyProperty()
+        throws Exception
+    {
+        on( bean ).getProperty( "writeOnlyProperty" ).get();
     }
 
 }



Mime
View raw message