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/beanutils/src/test/org/apache/commons/beanutils ConvertUtilsTestCase.java
Date Wed, 16 Apr 2003 08:36:35 GMT
rdonkin     2003/04/16 01:36:35

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        ConvertUtils.java
               beanutils/src/test/org/apache/commons/beanutils
                        ConvertUtilsTestCase.java
  Log:
  Committed fix for bug #18918. This bug prevented converters from being correctly deregistered.
Patch submitted by Eric Pugh.
  
  Revision  Changes    Path
  1.14      +16 -16    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConvertUtils.java	3 Mar 2003 22:33:46 -0000	1.13
  +++ ConvertUtils.java	16 Apr 2003 08:36:34 -0000	1.14
  @@ -66,7 +66,7 @@
    * <p>Utility methods for converting String scalar values to objects of the
    * specified Class, String arrays to arrays of the specified Class.</p>
    *
  - * <p>For more details, see <code>ConvertUtilsBean</code> which provides
the 
  + * <p>For more details, see <code>ConvertUtilsBean</code> which provides
the
    * implementations for these methods.</p>
    *
    * @author Craig R. McClanahan
  @@ -191,7 +191,7 @@
        *  Integer.class instead
        */
       public static void setDefaultInteger(int newDefaultInteger) {
  -	ConvertUtilsBean.getInstance().setDefaultInteger(newDefaultInteger);
  +        ConvertUtilsBean.getInstance().setDefaultInteger(newDefaultInteger);
       }
   
   
  @@ -240,7 +240,7 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#convert(Object)  
  +     * @see ConvertUtilsBean#convert(Object)
        */
       public static String convert(Object value) {
   
  @@ -255,11 +255,11 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#convert(String, Class)  
  +     * @see ConvertUtilsBean#convert(String, Class)
        */
       public static Object convert(String value, Class clazz) {
   
  -	return ConvertUtilsBean.getInstance().convert(value, clazz);
  +        return ConvertUtilsBean.getInstance().convert(value, clazz);
   
       }
   
  @@ -270,11 +270,11 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#convert(String[], Class)  
  +     * @see ConvertUtilsBean#convert(String[], Class)
        */
       public static Object convert(String values[], Class clazz) {
   
  -	return ConvertUtilsBean.getInstance().convert(values, clazz);
  +  return ConvertUtilsBean.getInstance().convert(values, clazz);
   
       }
   
  @@ -285,7 +285,7 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#deregister()  
  +     * @see ConvertUtilsBean#deregister()
        */
       public static void deregister() {
   
  @@ -300,11 +300,11 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#deregister(Class)  
  +     * @see ConvertUtilsBean#deregister(Class)
        */
       public static void deregister(Class clazz) {
   
  -        ConvertUtilsBean.getInstance().deregister();
  +        ConvertUtilsBean.getInstance().deregister(clazz);
   
       }
   
  @@ -316,7 +316,7 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#lookup(Class)  
  +     * @see ConvertUtilsBean#lookup(Class)
        */
       public static Converter lookup(Class clazz) {
   
  @@ -331,7 +331,7 @@
        *
        * <p>For more details see <code>ConvertUtilsBean</code>.</p>
        *
  -     * @see ConvertUtilsBean#register(Converter, Class)  
  +     * @see ConvertUtilsBean#register(Converter, Class)
        */
       public static void register(Converter converter, Class clazz) {
   
  
  
  
  1.7       +44 -26    jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/ConvertUtilsTestCase.java
  
  Index: ConvertUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/ConvertUtilsTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConvertUtilsTestCase.java	15 Mar 2003 11:38:11 -0000	1.6
  +++ ConvertUtilsTestCase.java	16 Apr 2003 08:36:34 -0000	1.7
  @@ -70,6 +70,7 @@
   import junit.framework.TestCase;
   import junit.framework.Test;
   import junit.framework.TestSuite;
  +import org.apache.commons.beanutils.converters.BooleanConverter;
   
   
   /**
  @@ -582,66 +583,83 @@
   
   
       }
  -    
  +
       public void testSeparateConvertInstances() throws Exception {
           ConvertUtilsBean utilsOne = new ConvertUtilsBean();
           ConvertUtilsBean utilsTwo = new ConvertUtilsBean();
  -        
  +
           // make sure that the test work ok before anything's changed
           Object
           value = utilsOne.convert("true", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(
  -                    "Standard conversion failed (1)", 
  -                    ((Boolean) value).booleanValue(), 
  +                    "Standard conversion failed (1)",
  +                    ((Boolean) value).booleanValue(),
                       true);
  -        
  +
           value = utilsTwo.convert("true", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(
  -                    "Standard conversion failed (2)", 
  -                    ((Boolean) value).booleanValue(), 
  +                    "Standard conversion failed (2)",
  +                    ((Boolean) value).booleanValue(),
                       true);
  -        
  +
           // now register a test
  -        
  +
           utilsOne.register(new ThrowExceptionConverter(), Boolean.TYPE);
           try {
  -            
  +
               utilsOne.convert("true", Boolean.TYPE);
               fail("Register converter failed.");
  -            
  +
           } catch (PassTestException e) { /* This shows that the registration has worked
*/ }
  -        
  +
           try {
               // nothing should have changed
               value = utilsTwo.convert("true", Boolean.TYPE);
               assertTrue(value instanceof Boolean);
               assertEquals(
                           "Standard conversion failed (3)",
  -                        ((Boolean) value).booleanValue(), 
  +                        ((Boolean) value).booleanValue(),
                           true);
  -            
  -        } catch (PassTestException e) { 
  -            // This is a failure since utilsTwo should still have 
  -            // standard converters registered 
  +
  +        } catch (PassTestException e) {
  +            // This is a failure since utilsTwo should still have
  +            // standard converters registered
               fail("Registering a converter for an instance should not effect another instance.");
           }
  -        
  +
           // nothing we'll test deregister
           utilsOne.deregister();
           value = utilsOne.convert("true", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals("Instance deregister failed.", ((Boolean) value).booleanValue(), true);
  -        
  +
           value = utilsTwo.convert("true", Boolean.TYPE);
           assertTrue(value instanceof Boolean);
           assertEquals(
  -                    "Standard conversion failed (4)", 
  -                    ((Boolean) value).booleanValue(), 
  +                    "Standard conversion failed (4)",
  +                    ((Boolean) value).booleanValue(),
  +                    true);
  +    }
  +
  +    public void testDeregisteringSingleConverter() throws Exception {
  +        ConvertUtils convertUtils = new ConvertUtils();
  +
  +        // make sure that the test work ok before anything's changed
  +        Object
  +        value = convertUtils.convert("true", Boolean.TYPE);
  +        assertTrue(value instanceof Boolean);
  +        assertEquals(
  +                    "Standard conversion failed (1)",
  +                    ((Boolean) value).booleanValue(),
                       true);
  -    }	
   
  +        // we'll test deregister
  +        convertUtils.deregister(Boolean.TYPE);
  +        assertNull("Converter should be null",convertUtils.lookup(Boolean.TYPE));
  +
  +    }
   
       // -------------------------------------------------------- Private Methods
   
  
  
  

---------------------------------------------------------------------
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