incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r938838 - in /incubator/bval/trunk/bval-jsr303/src: main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
Date Wed, 28 Apr 2010 09:37:35 GMT
Author: romanstumm
Date: Wed Apr 28 09:37:34 2010
New Revision: 938838

URL: http://svn.apache.org/viewvc?rev=938838&view=rev
Log:
BVAL-27 "I love it when a plan comes together" ;-) 
IllegalArgumentException should be thrown when calling BeanDescriptor.getConstraintsForProperty(null)
- fixed by Carlos

Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java?rev=938838&r1=938837&r2=938838&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
Wed Apr 28 09:37:34 2010
@@ -19,14 +19,13 @@
 package org.apache.bval.jsr303;
 
 
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.metadata.PropertyDescriptor;
-
 import org.apache.bval.model.Features;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.Validation;
 
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -77,6 +76,9 @@ public class BeanDescriptorImpl extends 
      * @param propertyName property evaludated
      */
     public PropertyDescriptor getConstraintsForProperty(String propertyName) {
+        if (propertyName == null || propertyName.isEmpty()) {
+            throw new IllegalArgumentException("propertyName cannot be null or empty");
+        }
         MetaProperty prop = metaBean.getProperty(propertyName);
         if (prop == null) return null;
         return getPropertyDescriptor(prop);

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java?rev=938838&r1=938837&r2=938838&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/ExceptionsContractTest.java
Wed Apr 28 09:37:34 2010
@@ -26,11 +26,12 @@ import javax.validation.ValidationExcept
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 import javax.validation.constraints.NotNull;
+import javax.validation.metadata.BeanDescriptor;
 import java.util.Locale;
 
 /**
- * Several checks to validate that the implementation of {@link Validator}
- * throws the correct exceptions as per the spec.
+ * Several checks to validate that the implementations of {@link Validator} and
+ * {@link BeanDescriptor} throw the correct exceptions as per the spec.
  * 
  * @author Carlos Vara
  */
@@ -196,6 +197,31 @@ public class ExceptionsContractTest exte
         }
     }
 
+    /**
+     * Checks that an {@link IllegalArgumentException} is thrown when calling
+     * {@link BeanDescriptor#getConstraintsForProperty(String)} with an invalid
+     * property name.
+     */
+    public void testGetConstraintsForInvalidProperty() {
+        Validator validator = getValidator();
+        BeanDescriptor personDescriptor = validator.getConstraintsForClass(Person.class);
+        
+        try {
+            personDescriptor.getConstraintsForProperty(null);
+            fail("No exception thrown when calling getConstraintsForProperty with null property");
+        } catch (IllegalArgumentException e) {
+            // Correct
+        }
+        
+        try {
+            personDescriptor.getConstraintsForProperty("");
+            fail("No exception thrown when calling getConstraintsForProperty with empty property");
+        } catch (IllegalArgumentException e) {
+            // Correct
+        }
+    }
+    
+
     public static class ExceptionThrowingBean {
 
         @NotNull



Mime
View raw message