commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert2 PackageTestSuite.java TestConvertUtils.java ProjectConvertTestSuite.java TestDefaultConversions.java
Date Sat, 20 Mar 2004 19:18:39 GMT
scolebourne    2004/03/20 11:18:39

  Added:       convert/src/test/org/apache/commons/convert
                        PackageTestSuite.java TestConvertUtils.java
                        TestDefaultConversions.java
                        ProjectConvertTestSuite.java
               convert/src/test/org/apache/commons/convert/conversion
                        TestTimeZoneToStringConversionFactory.java
                        TestNumberToIntegerConversionFactory.java
                        PackageTestSuite.java
                        TestClassToStringConversion.java
                        TestStringToIntegerConversion.java
                        TestIdentityConversionFactory.java
                        TestObjectToStringConversionFactory.java
                        TestDefaultValueDecorator.java
  Removed:     convert/src/test/org/apache/commons/convert2/conversion
                        TestIdentityConversionFactory.java
                        TestStringToIntegerConversion.java
                        TestObjectToStringConversionFactory.java
                        TestTimeZoneToStringConversionFactory.java
                        TestDefaultValueDecorator.java
                        TestNumberToIntegerConversionFactory.java
                        TestClassToStringConversion.java
                        PackageTestSuite.java
               convert/src/test/org/apache/commons/convert2
                        PackageTestSuite.java TestConvertUtils.java
                        ProjectConvertTestSuite.java
                        TestDefaultConversions.java
  Log:
  Rename convert2 to convert
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/PackageTestSuite.java
  
  Index: PackageTestSuite.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test suite.
   * 
   * @author Stephen Colebourne
   */
  public class PackageTestSuite extends TestCase {
  
      public PackageTestSuite(String name) {
          super(name);
      }
      
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite("Main package");
          suite.addTest(TestConvertUtils.suite());
          suite.addTest(TestDefaultConversions.suite());
          return suite;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/TestConvertUtils.java
  
  Index: TestConvertUtils.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  import java.util.TimeZone;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test case.
   * 
   * @author Stephen Colebourne
   */
  public class TestConvertUtils extends TestCase {
  
      public TestConvertUtils(String name) {
          super(name);
      }
      
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestConvertUtils.class, "ConvertUtils"));
      }
  
      //-----------------------------------------------------------------------
      public void testConvertToString() {
          assertEquals("true", ConvertUtils.convertToString(Boolean.TRUE));
          assertEquals("A", ConvertUtils.convertToString(new Character('A')));
          assertEquals("6", ConvertUtils.convertToString(new Byte((byte)6)));
          assertEquals("6", ConvertUtils.convertToString(new Short((short)6)));
          assertEquals("6", ConvertUtils.convertToString(new Integer(6)));
          assertEquals("6", ConvertUtils.convertToString(new Long(6)));
          assertEquals("6.0", ConvertUtils.convertToString(new Double(6)));
          assertEquals("6.0", ConvertUtils.convertToString(new Float(6)));
          assertEquals("Europe/Paris", ConvertUtils.convertToString(TimeZone.getTimeZone("Europe/Paris")));
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/TestDefaultConversions.java
  
  Index: TestDefaultConversions.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test case.
   * 
   * @author Stephen Colebourne
   */
  public class TestDefaultConversions extends TestCase {
  
      public TestDefaultConversions(String name) {
          super(name);
      }
      
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestDefaultConversions.class, "DefaultConversions"));
      }
  
      //-----------------------------------------------------------------------
      public void testCoversionBooleanToString() {
          assertEquals("true", ConvertUtils.convertToString(Boolean.TRUE));
          assertEquals("false", ConvertUtils.convertToString(Boolean.FALSE));
          assertEquals(null, ConvertUtils.convertToString(null, Boolean.class));
      }
      
      public void testCoversionCharacterToString() {
          assertEquals("A", ConvertUtils.convertToString(new Character('A')));
          assertEquals("a", ConvertUtils.convertToString(new Character('a')));
          assertEquals(null, ConvertUtils.convertToString(null, Character.class));
      }
      
      public void testCoversionByteToString() {
          assertEquals("0", ConvertUtils.convertToString(new Byte((byte) 0)));
          assertEquals("20", ConvertUtils.convertToString(new Byte((byte) 20)));
          assertEquals(null, ConvertUtils.convertToString(null, Byte.class));
      }
      
      public void testCoversionShortToString() {
          assertEquals("0", ConvertUtils.convertToString(new Short((short) 0)));
          assertEquals("20", ConvertUtils.convertToString(new Short((short) 20)));
          assertEquals(null, ConvertUtils.convertToString(null, Short.class));
      }
      
      public void testCoversionIntegerToString() {
          assertEquals("0", ConvertUtils.convertToString(new Integer(0)));
          assertEquals("20", ConvertUtils.convertToString(new Integer(20)));
          assertEquals(null, ConvertUtils.convertToString(null, Integer.class));
      }
      
      public void testCoversionLongToString() {
          assertEquals("0", ConvertUtils.convertToString(new Long(0)));
          assertEquals("20", ConvertUtils.convertToString(new Long(20)));
          assertEquals(null, ConvertUtils.convertToString(null, Long.class));
      }
      
      public void testCoversionFloatToString() {
          assertEquals("0.0", ConvertUtils.convertToString(new Float(0)));
          assertEquals("20.0", ConvertUtils.convertToString(new Float(20)));
          assertEquals(null, ConvertUtils.convertToString(null, Float.class));
      }
      
      public void testCoversionDoubleToString() {
          assertEquals("0.0", ConvertUtils.convertToString(new Double(0)));
          assertEquals("20.0", ConvertUtils.convertToString(new Double(20)));
          assertEquals(null, ConvertUtils.convertToString(null, Double.class));
      }
      
      public void testCoversionListToString() {
          assertEquals("[]", ConvertUtils.convertToString(new ArrayList()));
          assertEquals("[a, b, c]", ConvertUtils.convertToString(new ArrayList(Arrays.asList(new
Object[] {"a", "b", "c"}))));
          assertEquals(null, ConvertUtils.convertToString(null, List.class));
      }
      
      public void testCoversionMapToString() {
          assertEquals("{}", ConvertUtils.convertToString(new HashMap()));
          Map map = new HashMap();
          map.put("a", "A");
          map.put("b", "B");
          map.put("c", "C");
          assertEquals(map.toString(), ConvertUtils.convertToString(map));
          assertEquals(null, ConvertUtils.convertToString(null, List.class));
      }
      
      public void testCoversionClassToString() {
          assertEquals("java.lang.String", ConvertUtils.convertToString(String.class));
          assertEquals("java.util.Map", ConvertUtils.convertToString(Map.class));
          assertEquals(null, ConvertUtils.convertToString(null, Class.class));
      }
      
      public void testCoversionStringToString() {
          assertEquals("0", ConvertUtils.convertToString("0"));
          assertEquals("20", ConvertUtils.convertToString("20"));
          assertEquals(null, ConvertUtils.convertToString(null, String.class));
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/ProjectConvertTestSuite.java
  
  Index: ProjectConvertTestSuite.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test suite.
   * 
   * @author Stephen Colebourne
   */
  public class ProjectConvertTestSuite extends TestCase {
  
      public ProjectConvertTestSuite(String name) {
          super(name);
      }
      
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite("Convert");
          suite.addTest(org.apache.commons.convert.PackageTestSuite.suite());
          suite.addTest(org.apache.commons.convert.conversion.PackageTestSuite.suite());
          return suite;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestTimeZoneToStringConversionFactory.java
  
  Index: TestTimeZoneToStringConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  import java.util.SimpleTimeZone;
  import java.util.TimeZone;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestTimeZoneToStringConversionFactory extends TestCase {
  
      public TestTimeZoneToStringConversionFactory(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestTimeZoneToStringConversionFactory.class, "TimeZoneToString"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = TimeZoneToStringConversionFactory.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(false, Conversion.class.isAssignableFrom(TimeZoneToStringConversionFactory.class));
          assertEquals(true, ConversionFactory.class.isAssignableFrom(TimeZoneToStringConversionFactory.class));
      }
  
      public void testGetMatch() {
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
null, null));
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
TimeZone.class, null));
  
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
TimeZone.class, Object.class));
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
TimeZone.class, Integer.class));
  
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
Object.class, String.class));
          assertEquals(0, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
Integer.class, String.class));
          
          assertEquals(60, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
TimeZone.class, String.class));
          assertEquals(60, TimeZoneToStringConversionFactory.INSTANCE.getMatchPercent(null,
SimpleTimeZone.class, String.class));
      }
  
      public void testCoversionFromSimpleTimeZone() throws Exception {
          Converter converter = new Converter();
          Conversion conv = TimeZoneToStringConversionFactory.INSTANCE.getInstance(null, SimpleTimeZone.class,
String.class);
          assertEquals(SimpleTimeZone.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("GMT", conv.convert(new SimpleTimeZone(0, "GMT"), converter));
          assertEquals("GMT+1", conv.convert(new SimpleTimeZone(0, "GMT+1"), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromTimeZone() throws Exception {
          Converter converter = new Converter();
          Conversion conv = TimeZoneToStringConversionFactory.INSTANCE.getInstance(null, TimeZone.class,
String.class);
          assertEquals(TimeZone.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("GMT", conv.convert(TimeZone.getTimeZone("GMT"), converter));
          assertEquals("Europe/Paris", conv.convert(TimeZone.getTimeZone("Europe/Paris"),
converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestNumberToIntegerConversionFactory.java
  
  Index: TestNumberToIntegerConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestNumberToIntegerConversionFactory extends TestCase {
  
      public TestNumberToIntegerConversionFactory(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestNumberToIntegerConversionFactory.class, "NumberToInteger"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = NumberToIntegerConversionFactory.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(false, Conversion.class.isAssignableFrom(NumberToIntegerConversionFactory.class));
          assertEquals(true, ConversionFactory.class.isAssignableFrom(NumberToIntegerConversionFactory.class));
      }
  
      public void testGetMatch() {
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
null, null));
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Number.class, null));
  
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Number.class, Object.class));
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Number.class, Double.class));
  
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Object.class, String.class));
          assertEquals(0, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Integer.class, String.class));
  
          assertEquals(60, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Number.class, Integer.class));
          assertEquals(60, NumberToIntegerConversionFactory.INSTANCE.getMatchPercent(null,
Double.class, Integer.class));
      }
  
      public void testCoversionFromLong() throws Exception {
          Converter converter = new Converter();
          Conversion conv = NumberToIntegerConversionFactory.INSTANCE.getInstance(null, Long.class,
Integer.class);
  
          assertEquals(Long.class, conv.getFromType());
          assertEquals(Integer.class, conv.getToType());
          assertEquals(new Integer(6), conv.convert(new Long(6L), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromDouble() throws Exception {
          Converter converter = new Converter();
          Conversion conv = NumberToIntegerConversionFactory.INSTANCE.getInstance(null, Double.class,
Integer.class);
  
          assertEquals(Double.class, conv.getFromType());
          assertEquals(Integer.class, conv.getToType());
          assertEquals(new Integer(6), conv.convert(new Double(6d), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/PackageTestSuite.java
  
  Index: PackageTestSuite.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test suite.
   * 
   * @author Stephen Colebourne
   */
  public class PackageTestSuite extends TestCase {
  
      public PackageTestSuite(String name) {
          super(name);
      }
      
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite("Conversions");
          suite.addTest(TestClassToStringConversion.suite());
          suite.addTest(TestDefaultValueDecorator.suite());
          suite.addTest(TestIdentityConversionFactory.suite());
          suite.addTest(TestNumberToIntegerConversionFactory.suite());
          suite.addTest(TestObjectToStringConversionFactory.suite());
          suite.addTest(TestStringToIntegerConversion.suite());
          suite.addTest(TestTimeZoneToStringConversionFactory.suite());
          return suite;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestClassToStringConversion.java
  
  Index: TestClassToStringConversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestClassToStringConversion extends TestCase {
  
      public TestClassToStringConversion(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestClassToStringConversion.class, "ClassToString"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = ClassToStringConversion.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(true, Conversion.class.isAssignableFrom(ClassToStringConversion.class));
          assertEquals(false, ConversionFactory.class.isAssignableFrom(ClassToStringConversion.class));
      }
  
      public void testCoversion() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ClassToStringConversion.INSTANCE;
  
          assertEquals(Class.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("java.lang.String", conv.convert(String.class, converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestStringToIntegerConversion.java
  
  Index: TestStringToIntegerConversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestStringToIntegerConversion extends TestCase {
  
      public TestStringToIntegerConversion(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestStringToIntegerConversion.class, "NumberToInteger"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = StringToIntegerConversion.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(true, Conversion.class.isAssignableFrom(StringToIntegerConversion.class));
          assertEquals(false, ConversionFactory.class.isAssignableFrom(StringToIntegerConversion.class));
      }
  
      public void testCoversion() throws Exception {
          Converter converter = new Converter();
          Conversion conv = StringToIntegerConversion.INSTANCE;
  
          assertEquals(String.class, conv.getFromType());
          assertEquals(Integer.class, conv.getToType());
          assertEquals(new Integer(6), conv.convert("6", converter));
          assertEquals(null, conv.convert(null, converter));
          try {
              conv.convert("NoNumber", converter);
              fail();
          } catch (Exception ex) {}
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestIdentityConversionFactory.java
  
  Index: TestIdentityConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestIdentityConversionFactory extends TestCase {
  
      public TestIdentityConversionFactory(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestIdentityConversionFactory.class, "Identity"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = IdentityConversionFactory.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(false, Conversion.class.isAssignableFrom(IdentityConversionFactory.class));
          assertEquals(true, ConversionFactory.class.isAssignableFrom(IdentityConversionFactory.class));
      }
  
      public void testGetMatch() {
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, null, null));
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, String.class,
null));
  
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, String.class,
Object.class));
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, String.class,
Integer.class));
  
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, Object.class,
String.class));
          assertEquals(0, IdentityConversionFactory.INSTANCE.getMatchPercent(null, Integer.class,
String.class));
          
          assertEquals(80, IdentityConversionFactory.INSTANCE.getMatchPercent(null, String.class,
String.class));
          assertEquals(80, IdentityConversionFactory.INSTANCE.getMatchPercent(null, Integer.class,
Integer.class));
      }
  
      public void testCoversionString() throws Exception {
          Converter converter = new Converter();
          Conversion conv = IdentityConversionFactory.INSTANCE.getInstance(null, String.class,
String.class);
          String str = "ABCDE";
          
          assertEquals(String.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertSame(str, conv.convert(str, converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionInteger() throws Exception {
          Converter converter = new Converter();
          Conversion conv = IdentityConversionFactory.INSTANCE.getInstance(null, Integer.class,
Integer.class);
          Integer six = new Integer(6);
          
          assertEquals(Integer.class, conv.getFromType());
          assertEquals(Integer.class, conv.getToType());
          assertSame(six, conv.convert(six, converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestObjectToStringConversionFactory.java
  
  Index: TestObjectToStringConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class.
   * 
   * @author Stephen Colebourne
   */
  public class TestObjectToStringConversionFactory extends TestCase {
  
      public TestObjectToStringConversionFactory(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestObjectToStringConversionFactory.class, "ObjectToString"));
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = ObjectToStringConversionFactory.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(false, Conversion.class.isAssignableFrom(ObjectToStringConversionFactory.class));
          assertEquals(true, ConversionFactory.class.isAssignableFrom(ObjectToStringConversionFactory.class));
      }
  
      public void testGetMatch() {
          assertEquals(0, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null, null,
null));
          assertEquals(0, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null, Object.class,
null));
  
          assertEquals(0, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null, Object.class,
Object.class));
          assertEquals(0, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null, Object.class,
Integer.class));
  
          assertEquals(20, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null,
Object.class, String.class));
          assertEquals(20, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null,
String.class, String.class));
          assertEquals(20, ObjectToStringConversionFactory.INSTANCE.getMatchPercent(null,
Integer.class, String.class));
      }
  
      //-----------------------------------------------------------------------
      public void testCoversionFromBoolean() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Boolean.class,
String.class);
          assertEquals(Boolean.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("true", conv.convert(Boolean.TRUE, converter));
          assertEquals("false", conv.convert(Boolean.FALSE, converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromCharacter() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Character.class,
String.class);
          assertEquals(Character.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("A", conv.convert(new Character('A'), converter));
          assertEquals("a", conv.convert(new Character('a'), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromByte() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Byte.class,
String.class);
          assertEquals(Byte.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("0", conv.convert(new Byte((byte) 0), converter));
          assertEquals("20", conv.convert(new Byte((byte) 20), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromShort() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Short.class,
String.class);
          assertEquals(Short.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("0", conv.convert(new Short((short) 0), converter));
          assertEquals("20", conv.convert(new Short((short) 20), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromInteger() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Integer.class,
String.class);
          assertEquals(Integer.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("0", conv.convert(new Integer(0), converter));
          assertEquals("20", conv.convert(new Integer(20), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromLong() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, Long.class,
String.class);
          assertEquals(Long.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("0", conv.convert(new Long(0), converter));
          assertEquals("20", conv.convert(new Long(20), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromList() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, List.class,
String.class);
          assertEquals(List.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("[]", conv.convert(new ArrayList(), converter));
          assertEquals(
              "[a, b, c]",
              conv.convert(new ArrayList(Arrays.asList(new Object[] { "a", "b", "c" })), converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
      public void testCoversionFromString() throws Exception {
          Converter converter = new Converter();
          Conversion conv = ObjectToStringConversionFactory.INSTANCE.getInstance(null, String.class,
String.class);
          assertEquals(String.class, conv.getFromType());
          assertEquals(String.class, conv.getToType());
          assertEquals("0", conv.convert("0", converter));
          assertEquals("20", conv.convert("20", converter));
          assertEquals(null, conv.convert(null, converter));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/test/org/apache/commons/convert/conversion/TestDefaultValueDecorator.java
  
  Index: TestDefaultValueDecorator.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Modifier;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Test class for DefaultValueConversionDecorator.
   * 
   * @author Oliver Heger
   * @author Stephen Colebourne
   */
  public class TestDefaultValueDecorator extends TestCase {
  
      private static final MockConversion MOCK = new MockConversion();
      private static final Integer ONE = new Integer(1);
      private static final Integer DEFAULT = new Integer(42);
      
      Converter converter;
      Conversion baseConversion;
      
      public TestDefaultValueDecorator(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return (new TestSuite(TestDefaultValueDecorator.class, "DefaultValueDecorator"));
      }
  
      protected void setUp() throws Exception {
          converter = new Converter();
          baseConversion = StringToIntegerConversion.INSTANCE;
      }
  
      //-----------------------------------------------------------------------
      public void testClass() {
          Constructor[] con = DefaultValueDecorator.class.getDeclaredConstructors();
          assertEquals(1, con.length);
          assertEquals(true, Modifier.isProtected(con[0].getModifiers()));
          assertEquals(false, Conversion.class.isAssignableFrom(DefaultValueDecorator.class));
          assertEquals(false, ConversionFactory.class.isAssignableFrom(DefaultValueDecorator.class));
      }
  
      //-----------------------------------------------------------------------
      public void testDefaultNullInputConversion() throws Exception {
          Conversion conv = DefaultValueDecorator.defaultNullInput(baseConversion, DEFAULT);
          converter.getRegistry().addConversion(conv);
  
          assertEquals(DEFAULT, conv.convert(null, converter));
          assertEquals(ONE, conv.convert("1", converter));
          try {
              conv.convert("NoNumber", converter);
              fail();
          } catch (Exception ex) {}
          
          Conversion mock = DefaultValueDecorator.defaultNullInput(MOCK, null);
          MockConversion.called = 0;
          mock.convert(null, converter);
          assertEquals(0, MockConversion.called);
          
          MockConversion.called = 0;
          mock.convert("1", converter);
          assertEquals(1, MockConversion.called);
      }
  
      public void testDefaultNullResultConversion() throws Exception {
          Conversion conv = DefaultValueDecorator.defaultNullResult(baseConversion, DEFAULT);
          converter.getRegistry().addConversion(conv);
  
          assertEquals(DEFAULT, conv.convert(null, converter));
          assertEquals(ONE, conv.convert("1", converter));
          try {
              conv.convert("NoNumber", converter);
              fail();
          } catch (Exception ex) {}
          
          Conversion mock = DefaultValueDecorator.defaultNullResult(MOCK, null);
          MockConversion.called = 0;
          mock.convert(null, converter);
          assertEquals(1, MockConversion.called);
          
          MockConversion.called = 0;
          mock.convert("1", converter);
          assertEquals(1, MockConversion.called);
      }
  
      public void testDefaultExceptionConversion() throws Exception {
          Conversion conv = DefaultValueDecorator.defaultException(baseConversion, DEFAULT);
          converter.getRegistry().addConversion(conv);
  
          assertEquals(null, conv.convert(null, converter));
          assertEquals(ONE, conv.convert("1", converter));
          assertEquals(DEFAULT, conv.convert("NoNumber", converter));
          
          Conversion mock = DefaultValueDecorator.defaultException(MOCK, null);
          MockConversion.called = 0;
          mock.convert(null, converter);
          assertEquals(1, MockConversion.called);
          
          MockConversion.called = 0;
          mock.convert("1", converter);
          assertEquals(1, MockConversion.called);
      }
  
      public void testNullAndExceptionConversion() throws Exception {
          Conversion conv = DefaultValueDecorator.defaultNullAndException(baseConversion,
DEFAULT);
          converter.getRegistry().addConversion(conv);
  
          assertEquals(DEFAULT, conv.convert(null, converter));
          assertEquals(ONE, conv.convert("1", converter));
          assertEquals(DEFAULT, conv.convert("NoNumber", converter));
          
          Conversion mock = DefaultValueDecorator.defaultNullAndException(MOCK, null);
          MockConversion.called = 0;
          mock.convert(null, converter);
          assertEquals(0, MockConversion.called);
          
          MockConversion.called = 0;
          mock.convert("1", converter);
          assertEquals(1, MockConversion.called);
      }
  
      static class MockConversion implements Conversion {
          static int called = 0;
  
          public Object convert(Object value, Converter converter) throws Exception {
              called++;
              return null;
          }
  
          public Class getFromType() {
              return null;
          }
  
          public Class getToType() {
              return null;
          }
      }
  }
  
  
  

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