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.array;
017    
018    import junit.framework.TestCase;
019    import junit.framework.TestSuite;
020    
021    import org.apache.commons.convert1.Converter;
022    
023    import org.apache.commons.convert1.string.LongConverter;
024    
025    
026    /**
027     * Test Case for the ArrayConverter class.
028     *
029     * @author Henri Yandell
030     * @version $Id: ArrayConverterTestCase.java 155441 2005-02-26 13:19:22Z dirkv $
031     */
032    
033    public class ArrayConverterTestCase extends TestCase {
034    
035        // ------------------------------------------------------------------------
036    
037        public ArrayConverterTestCase(String name) {
038            super(name);
039        }
040        
041        // ------------------------------------------------------------------------
042    
043        public void setUp() throws Exception {
044        }
045    
046        public static TestSuite suite() {
047            return new TestSuite(ArrayConverterTestCase.class);        
048        }
049    
050        public void tearDown() throws Exception {
051        }
052    
053        // ------------------------------------------------------------------------
054    
055        public void testLongConvert() {
056            ArrayConverter converter = new ArrayConverter( new LongConverter() );
057            assertEqualArray( new Long[] { new Long(0), new Long(1) }, (Long[]) converter.convert(Long.class, "0,1") );
058        }
059    
060        public void testPrimitiveLongConvert() {
061            ArrayConverter converter = new ArrayConverter( new LongConverter() );
062            assertEqualArray( new long[] { 0L, 1L }, (long[]) converter.convert(Long.TYPE, "0,1") );
063        }
064    
065        private void assertEqualArray(Object[] array1, Object[] array2) {
066            assertEquals( "Unequal length", array1.length, array2.length );
067            for(int i=0; i<array1.length; i++) {
068                assertEquals( "Unequal element in array index of "+i,  array1[i], array2[i] );
069            }
070        }
071    
072        private void assertEqualArray(long[] array1, long[] array2) {
073            assertEquals( "Unequal length", array1.length, array2.length );
074            for(int i=0; i<array1.length; i++) {
075                assertEquals( "Unequal element in array index of "+i,  array1[i], array2[i] );
076            }
077        }
078    }