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/converters ConverterTestSuite.java StringArrayConverterTestCase.java
Date Wed, 26 Mar 2003 20:24:41 GMT
rdonkin     2003/03/26 12:24:41

  Modified:    beanutils build.xml
               beanutils/src/java/org/apache/commons/beanutils/converters
                        StringArrayConverter.java
  Added:       beanutils/src/test/org/apache/commons/beanutils/converters
                        ConverterTestSuite.java
                        StringArrayConverterTestCase.java
  Log:
  Added conversion of int[] to StringArrayConverter. This helps with a common html forms use
case. Enhancement filed as bug #18297. Patch submitted by Dan Allen.
  
  Revision  Changes    Path
  1.52      +19 -2     jakarta-commons/beanutils/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/build.xml,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- build.xml	9 Mar 2003 21:25:16 -0000	1.51
  +++ build.xml	26 Mar 2003 20:24:40 -0000	1.52
  @@ -262,7 +262,8 @@
                                   test.dyna.result,
                                   test.dyna.row,
                                   test.bean.comparator,
  -                                test.locale.convert
  +                                test.locale.convert,
  +                                test.converters
                                  "
      description="Run all unit test cases">
     </target>
  @@ -444,6 +445,22 @@
         <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
                    value="${test.level}"/>
         <arg value="org.apache.commons.beanutils.locale.LocaleConvertTestSuite"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +  </target>
  +  
  +  
  +  <target name="test.converters" depends="compile.tests">
  +    <echo message="Running Converters tests ..."/>
  +    <java classname="${test.runner}" fork="yes"
  +        failonerror="${test.failonerror}">
  +      <sysproperty key="org.apache.commons.logging.LogFactory"
  +                 value="${test.factory}"/>
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="${test.log}"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
  +                 value="${test.level}"/>
  +      <arg value="org.apache.commons.beanutils.converters.ConverterTestSuite"/>
         <classpath refid="test.classpath"/>
       </java>
     </target>
  
  
  
  1.4       +23 -4     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/StringArrayConverter.java
  
  Index: StringArrayConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/StringArrayConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringArrayConverter.java	15 Jan 2003 21:59:41 -0000	1.3
  +++ StringArrayConverter.java	26 Mar 2003 20:24:40 -0000	1.4
  @@ -118,6 +118,12 @@
        * <p>Model object for type comparisons.</p>
        */
       private static String model[] = new String[0];
  +    
  +    /**
  +     * <p> Model object for int arrays.</p>
  +     */
  +    private static int ints[] = new int[0];
  +
   
   
       // --------------------------------------------------------- Public Methods
  @@ -147,6 +153,19 @@
           // Deal with the no-conversion-needed case
           if (model.getClass() == value.getClass()) {
               return (value);
  +        }
  +
  +        // Deal with the input value as an int array
  +        if (ints.getClass() == value.getClass())
  +        {
  +            int[] values = (int[]) value;
  +            String[] results = new String[values.length];
  +            for (int i = 0; i < values.length; i++)
  +            {
  +                results[i] = Integer.toString(values[i]);
  +            }
  +
  +            return (results);
           }
   
           // Parse the input value as a String into elements
  
  
  
  1.1                  jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ConverterTestSuite.java
  
  Index: ConverterTestSuite.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/ConverterTestSuite.java,v
1.1 2003/03/26 20:24:40 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/26 20:24:40 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.beanutils.converters;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * <p>
   * Created a test suite so that new test cases can be added here without having to
   * edit the build.xml.
   * </p>
   *
   * @author  Robert Burrell Donkin
   * @version $Revision: 1.1 $ $Date: 2003/03/26 20:24:40 $
   */
  
  public class ConverterTestSuite {
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          TestSuite testSuite = new TestSuite();
          testSuite.addTestSuite(ByteConverterTestCase.class);
          testSuite.addTestSuite(DoubleConverterTestCase.class);
          testSuite.addTestSuite(FloatConverterTestCase.class);
          testSuite.addTestSuite(IntegerConverterTestCase.class);
          testSuite.addTestSuite(LongConverterTestCase.class);
          testSuite.addTestSuite(ShortConverterTestCase.class);
          testSuite.addTestSuite(StringArrayConverterTestCase.class);
          return testSuite;
      }
  }
  
  
  
  
  1.1                  jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/StringArrayConverterTestCase.java
  
  Index: StringArrayConverterTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/converters/StringArrayConverterTestCase.java,v
1.1 2003/03/26 20:24:40 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/26 20:24:40 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.beanutils.converters;
  
  import junit.framework.TestCase;
  import junit.framework.TestCase;
  
  /**
   * Test Case for StringArrayConverter
   *
   * @author Robert Burrell Donkin
   * @version $Revision: 1.1 $ $Date: 2003/03/26 20:24:40 $
   */
  
  public class StringArrayConverterTestCase extends TestCase {
      
      public StringArrayConverterTestCase(String name) {
          super(name);
      }
      
      public void testIntToString() {
          
          int[] testArray = {1, 2, 3, 4, 5};
          String[] results = (String []) new StringArrayConverter().convert(String.class,
testArray);
          
          assertEquals("Incorrect results size", 5, results.length);
          assertEquals("Entry one is wrong", "1", results[0]); 
          assertEquals("Entry two is wrong", "2", results[1]); 
          assertEquals("Entry three is wrong", "3", results[2]); 
          assertEquals("Entry four is wrong", "4", results[3]); 
          assertEquals("Entry five is wrong", "5", results[4]); 
      }
  }
  
  
  
  

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