001 /*
002 * Copyright 2003-2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.apache.commons.convert1;
017 import junit.framework.Test;
018 import junit.framework.TestCase;
019 import junit.framework.TestSuite;
020
021 public class ConvertRegistryTestCase extends TestCase {
022
023 /**
024 * Construct a new instance of this test case.
025 *
026 * @param name Name of the test case
027 */
028 public ConvertRegistryTestCase(String name) {
029 super(name);
030 }
031
032
033 /**
034 * Set up instance variables required by this test case.
035 */
036 public void setUp() {
037 ; // No action required
038 }
039
040
041 /**
042 * Return the tests included in this test suite.
043 */
044 public static Test suite() {
045 return (new TestSuite(ConvertRegistryTestCase.class));
046 }
047
048
049 /**
050 * Tear down instance variables required by this test case.
051 */
052 public void tearDown() {
053 ; // No action required
054 }
055
056 public void testRegister() {
057 ConvertRegistry creg = new ConvertRegistry();
058 Converter con = new IdentityConverter();
059 creg.register(con, String.class, Long.class);
060 assertEquals(con, creg.lookup(String.class, Long.class) );
061 }
062
063 public void testLookupInheritence() {
064 ConvertRegistry creg = new ConvertRegistry();
065
066 Converter con1 = new IdentityConverter();
067 Converter con2 = new IdentityConverter();
068
069 creg.register(con1, String.class, Number.class);
070 assertEquals(con1, creg.lookup(String.class, Number.class) );
071 assertEquals(con1, creg.lookup(String.class, Long.class) );
072 assertEquals(con1, creg.lookup(String.class, Double.class) );
073 assertNull(creg.lookup(String.class, String.class));
074
075 creg.clear();
076
077 creg.register(con1, Object.class, Number.class);
078 creg.register(con2, String.class, Long.class);
079 assertEquals(con2, creg.lookup(String.class, Long.class) );
080 assertEquals(con1, creg.lookup(String.class, Double.class) );
081 assertEquals(con1, creg.lookup(String.class, Short.class) );
082 assertNull(creg.lookup(Double.class, String.class) );
083 creg.clear();
084
085 creg.register(con1, java.util.Date.class, Comparable.class);
086 creg.register(con2, java.sql.Date.class, String.class);
087 assertEquals(con1, creg.lookup(java.sql.Date.class, Long.class) );
088 }
089
090 }