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.string;
017    
018    import java.io.File;
019    
020    import junit.framework.TestCase;
021    import junit.framework.TestSuite;
022    
023    import org.apache.commons.convert1.Converter;
024    
025    
026    /**
027     * Test Case for the FileConverter class.
028     *
029     * @author James Strachan
030     * @version $Id: FileConverterTestCase.java 155441 2005-02-26 13:19:22Z dirkv $
031     */
032    
033    public class FileConverterTestCase extends TestCase {
034    
035        private Converter converter = null;
036    
037        // ------------------------------------------------------------------------
038    
039        public FileConverterTestCase(String name) {
040            super(name);
041        }
042        
043        // ------------------------------------------------------------------------
044    
045        public void setUp() throws Exception {
046            converter = makeConverter();
047        }
048    
049        public static TestSuite suite() {
050            return new TestSuite(FileConverterTestCase.class);        
051        }
052    
053        public void tearDown() throws Exception {
054            converter = null;
055        }
056    
057        // ------------------------------------------------------------------------
058        
059        protected Converter makeConverter() {
060            return new FileConverter();
061        }
062        
063        protected Class getExpectedType() {
064            return File.class;
065        }
066    
067        // ------------------------------------------------------------------------
068    
069        public void testSimpleConversion() throws Exception {
070            String[] message= { 
071                "from String",
072                "from String",
073                "from String"
074            };
075            
076            Object[] input = { 
077                "/tmp",
078                "/tmp/foo.txt",
079                "/tmp/does/not/exist.foo"
080            };
081            
082            File[] expected = { 
083                new File("/tmp"),
084                new File("/tmp/foo.txt"),
085                new File("/tmp/does/not/exist.foo")
086            };
087            
088            for(int i=0;i<expected.length;i++) {
089                assertEquals(message[i] + " to File",expected[i],converter.convert(File.class,input[i]));
090                assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
091            }
092        }
093        
094    }
095