You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by cr...@apache.org on 2003/07/03 21:10:27 UTC

cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils PropertyUtilsTestCase.java TestBean.java

craigmcc    2003/07/03 12:10:27

  Modified:    beanutils/src/test/org/apache/commons/beanutils
                        PropertyUtilsTestCase.java TestBean.java
  Log:
  Add a unit test to verify the current JDK introspection of a bean with
  the following method signatures:
  
    public boolean isFoo();
    public boolean getFoo();
    public void setFoo(String foo);
  
  According to Section 8.3.1 of the JavaBeans Specification, this
  will get recognized as a read-only boolean property using "isFoo"
  as the getter method.  Therefore, all of the code in commons-beanutils
  should make this same assumption as well.
  
  One could argue that it would make more sense to not recognize "foo"
  as a property at all, since the types on the getter and setter methods
  are different.  However, that's not the way the JavaBeans spec is worded,
  and not the way that the JDK's introspection logic works either.
  
  Revision  Changes    Path
  1.31      +31 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
  
  Index: PropertyUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- PropertyUtilsTestCase.java	12 May 2003 21:42:56 -0000	1.30
  +++ PropertyUtilsTestCase.java	3 Jul 2003 19:10:27 -0000	1.31
  @@ -452,6 +452,33 @@
   
   
       /**
  +     * <p>Negative tests on an invalid property with two different boolean
  +     * getters (which is fine, according to the JavaBeans spec) but a
  +     * String setter instead of a boolean setter.</p>
  +     *
  +     * <p>Although one could logically argue that this combination of method
  +     * signatures should not identify a property at all, there is a sentence
  +     * in Section 8.3.1 making it clear that the behavior tested for here
  +     * is correct:  "If we find only one of these methods, then we regard
  +     * it as defining either a read-only or write-only property called
  +     * <em>&lt;property-name&gt;</em>.</p>
  +     */
  +    public void testGetDescriptorInvalidBoolean() throws Exception {
  +
  +	PropertyDescriptor pd =
  +	    PropertyUtils.getPropertyDescriptor(bean, "invalidBoolean");
  +	assertNotNull("invalidBoolean is a property", pd);
  +	assertNotNull("invalidBoolean has a getter method",
  +		      pd.getReadMethod());
  +	assertNull("invalidBoolean has no write method",
  +		   pd.getWriteMethod());
  +	assertTrue("invalidBoolean getter method is isInvalidBoolean",
  +		   "isInvalidBoolean".equals(pd.getReadMethod().getName()));
  +
  +    }
  +
  +
  +    /**
        * Positive getPropertyDescriptor on property <code>longProperty</code>.
        */
       public void testGetDescriptorLong() {
  
  
  
  1.16      +35 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestBean.java	1 Feb 2003 07:45:29 -0000	1.15
  +++ TestBean.java	3 Jul 2003 19:10:27 -0000	1.16
  @@ -525,6 +525,37 @@
       }
   
   
  +    // ------------------------------------------------------ Invalid Properties
  +
  +
  +    /**
  +     * <p>An invalid property that has two boolean getters (getInvalidBoolean
  +     * and isInvalidBoolean) plus a String setter (setInvalidBoolean).  By the
  +     * rules described in the JavaBeans Specification, this will be considered
  +     * a read-only boolean property, using isInvalidBoolean() as the getter.</p>
  +     */
  +    private boolean invalidBoolean = false;
  +
  +    public boolean getInvalidBoolean() {
  +	return (this.invalidBoolean);
  +    }
  +
  +    public boolean isInvalidBoolean() {
  +	return (this.invalidBoolean);
  +    }
  +
  +    public void setInvalidBoolean(String invalidBoolean) {
  +	if ("true".equalsIgnoreCase(invalidBoolean) ||
  +	    "yes".equalsIgnoreCase(invalidBoolean) ||
  +	    "1".equalsIgnoreCase(invalidBoolean)) {
  +	    this.invalidBoolean = true;
  +	} else {
  +	    this.invalidBoolean = false;
  +	}
  +    }
  +
  +
  +
       // ------------------------------------------------------- Static Variables
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org