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.util;
017    
018    import java.util.Iterator;
019    
020    import junit.framework.Test;
021    import junit.framework.TestCase;
022    import junit.framework.TestSuite;
023    
024    public class BasicInheritorTestCase extends TestCase {
025    
026        /**
027         * Construct a new instance of this test case.
028         *
029         * @param name Name of the test case
030         */
031        public BasicInheritorTestCase(String name) {
032            super(name);
033        }
034    
035        /**
036         * Set up instance variables required by this test case.
037         */
038        public void setUp() {
039            ;    // No action required
040        }
041        
042        /**
043         * Return the tests included in this test suite.
044         */
045        public static Test suite() {
046            return (new TestSuite(BasicInheritorTestCase.class));
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 testString() {
057            BasicInheritor btr = new BasicInheritor(String.class);
058            // jdk 1.4 :(
059            assertCorrect(btr, String.class, new Class[] { java.io.Serializable.class, Comparable.class, CharSequence.class } );
060        }
061        
062        public void testInteger() {
063            BasicInheritor btr = new BasicInheritor(Integer.class);
064            assertCorrect(btr, Integer.class, new Class[] { Number.class, Comparable.class, java.io.Serializable.class } );
065        }
066        
067        private void assertCorrect(BasicInheritor btr, Class clazz, Class[] parents) {
068            Iterator itr = btr.iterator();
069            assertEquals( "Inheritor should start with the original class", 
070                          clazz, itr.next());
071            for (int i = 0; i < parents.length; i++) {
072                assertEquals(parents[i], itr.next());
073            }
074    
075            assertEquals( "Inheritor should end with Object", 
076                          Object.class, itr.next() );
077    
078            if (itr.hasNext()) {
079                fail("Inheritor should not continue after Object");
080            }
081        }
082        
083    }