1   /*
2    *  Copyright 2003-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.apache.commons.convert1;
17  import junit.framework.Test;
18  import junit.framework.TestCase;
19  import junit.framework.TestSuite;
20  
21  public class ConvertRegistryTestCase extends TestCase {
22  
23      /**
24       * Construct a new instance of this test case.
25       *
26       * @param name Name of the test case
27       */
28      public ConvertRegistryTestCase(String name) {
29          super(name);
30      }
31  
32  
33      /**
34       * Set up instance variables required by this test case.
35       */
36      public void setUp() {
37          ;    // No action required
38      }
39  
40  
41      /**
42       * Return the tests included in this test suite.
43       */
44      public static Test suite() {
45          return (new TestSuite(ConvertRegistryTestCase.class));
46      }
47  
48  
49      /**
50       * Tear down instance variables required by this test case.
51       */
52      public void tearDown() {
53          ;    // No action required
54      }
55      
56      public void testRegister() {
57          ConvertRegistry creg = new ConvertRegistry();
58          Converter con = new IdentityConverter();
59          creg.register(con, String.class, Long.class);
60          assertEquals(con, creg.lookup(String.class, Long.class) );
61      }
62      
63      public void testLookupInheritence() {
64          ConvertRegistry creg = new ConvertRegistry();
65  
66          Converter con1 = new IdentityConverter();
67          Converter con2 = new IdentityConverter();
68  
69          creg.register(con1, String.class, Number.class);
70          assertEquals(con1, creg.lookup(String.class, Number.class) );
71          assertEquals(con1, creg.lookup(String.class, Long.class) );
72          assertEquals(con1, creg.lookup(String.class, Double.class) );
73          assertNull(creg.lookup(String.class, String.class));
74  
75          creg.clear();
76          
77          creg.register(con1, Object.class, Number.class);
78          creg.register(con2, String.class, Long.class);
79          assertEquals(con2, creg.lookup(String.class, Long.class) );
80          assertEquals(con1, creg.lookup(String.class, Double.class) );
81          assertEquals(con1, creg.lookup(String.class, Short.class) );
82          assertNull(creg.lookup(Double.class, String.class) );
83          creg.clear();
84          
85          creg.register(con1, java.util.Date.class, Comparable.class);
86          creg.register(con2, java.sql.Date.class, String.class);
87          assertEquals(con1, creg.lookup(java.sql.Date.class, Long.class) );
88      }
89      
90  }