commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester CallMethodRuleTestCase.java PrimitiveBean.java
Date Mon, 14 Apr 2003 21:31:04 GMT
rdonkin     2003/04/14 14:31:04

  Modified:    digester/src/java/org/apache/commons/digester
                        CallMethodRule.java
               digester/src/test/org/apache/commons/digester
                        CallMethodRuleTestCase.java PrimitiveBean.java
  Log:
  Fix for backwards compatibilty issue. CallMethodRule used to convert all nulls using ConvertUtils.
Digester 1.4.1 added some functionality which removed this feature. This fix adds it back.
Plus a test case.
  
  Revision  Changes    Path
  1.21      +10 -6     jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java
  
  Index: CallMethodRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CallMethodRule.java	2 Feb 2003 16:09:53 -0000	1.20
  +++ CallMethodRule.java	14 Apr 2003 21:31:03 -0000	1.21
  @@ -445,8 +445,12 @@
           // the specified paramType is not String. 
           Object paramValues[] = new Object[paramTypes.length];
           for (int i = 0; i < paramTypes.length; i++) {
  -            if(parameters[i] instanceof String && 
  -               !String.class.isAssignableFrom(paramTypes[i])) {
  +            // convert nulls and convert stringy parameters 
  +            // for non-stringy param types
  +            if(
  +                parameters[i] == null
  +                || (parameters[i] instanceof String && 
  +                   !String.class.isAssignableFrom(paramTypes[i]))) {
                   
                   paramValues[i] =
                           ConvertUtils.convert((String) parameters[i], paramTypes[i]);
  
  
  
  1.5       +20 -2     jakarta-commons/digester/src/test/org/apache/commons/digester/CallMethodRuleTestCase.java
  
  Index: CallMethodRuleTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/CallMethodRuleTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CallMethodRuleTestCase.java	13 Apr 2003 20:46:03 -0000	1.4
  +++ CallMethodRuleTestCase.java	14 Apr 2003 21:31:04 -0000	1.5
  @@ -328,7 +328,9 @@
   
       public void testPrimitiveReading() throws Exception {
           StringReader reader = new StringReader(
  -            "<?xml version='1.0' ?><root><bean good='true'/><bean
good='false'/><bean/></root>");
  +            "<?xml version='1.0' ?><root><bean good='true'/><bean
good='false'/><bean/>"
  +            + "<beanie bad='Fee Fie Foe Fum' good='true'/><beanie bad='Fee Fie
Foe Fum' good='false'/>"
  +            + "<beanie bad='Fee Fie Foe Fum'/></root>");
               
           Digester digester = new Digester();
           
  @@ -342,11 +344,18 @@
           digester.addCallMethod("root/bean", "setBoolean", 1, params);
           digester.addCallParam("root/bean", 0, "good");
           
  +        digester.addObjectCreate("root/beanie", PrimitiveBean.class);
  +        digester.addSetNext("root/beanie", "add");
  +        Class [] beanieParams = { String.class, Boolean.TYPE };
  +        digester.addCallMethod("root/beanie", "testSetBoolean", 2, beanieParams);
  +        digester.addCallParam("root/beanie", 0, "bad");
  +        digester.addCallParam("root/beanie", 1, "good");
  +        
           ArrayList list = new ArrayList();
           digester.push(list);
           digester.parse(reader);
           
  -        assertEquals("Wrong number of beans in list", 3, list.size());
  +        assertEquals("Wrong number of beans in list", 6, list.size());
           PrimitiveBean bean = (PrimitiveBean) list.get(0);
           assertTrue("Bean 0 property not called", bean.getSetBooleanCalled());
           assertEquals("Bean 0 property incorrect", true, bean.getBoolean());
  @@ -356,6 +365,15 @@
           bean = (PrimitiveBean) list.get(2);
           // no attibute, no call is what's expected
           assertTrue("Bean 2 property called", !bean.getSetBooleanCalled());
  +        bean = (PrimitiveBean) list.get(3);
  +        assertTrue("Bean 3 property not called", bean.getSetBooleanCalled());
  +        assertEquals("Bean 3 property incorrect", true, bean.getBoolean());
  +        bean = (PrimitiveBean) list.get(4);
  +        assertTrue("Bean 4 property not called", bean.getSetBooleanCalled());
  +        assertEquals("Bean 4 property incorrect", false, bean.getBoolean());
  +        bean = (PrimitiveBean) list.get(5);
  +        assertTrue("Bean 5 property not called", bean.getSetBooleanCalled());
  +        assertEquals("Bean 5 property incorrect", false, bean.getBoolean());       
       }
       
       public void testFromStack() throws Exception {
  
  
  
  1.2       +7 -3      jakarta-commons/digester/src/test/org/apache/commons/digester/PrimitiveBean.java
  
  Index: PrimitiveBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/PrimitiveBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrimitiveBean.java	13 Apr 2003 20:46:03 -0000	1.1
  +++ PrimitiveBean.java	14 Apr 2003 21:31:04 -0000	1.2
  @@ -88,4 +88,8 @@
           this.booleanValue = booleanValue;
           setBooleanCalled = true;
       }
  +    
  +    public void testSetBoolean(String ignored, boolean booleanValue) {
  +        setBoolean(booleanValue);
  +    }
   }
  
  
  

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


Mime
View raw message