1 16 17 package org.apache.commons.beanutils.converters; 18 19 import java.io.File ; 20 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 import org.apache.commons.beanutils.Converter; 25 26 27 33 34 public class FileConverterTestCase extends TestCase { 35 36 private Converter converter = null; 37 38 40 public FileConverterTestCase(String name) { 41 super(name); 42 } 43 44 46 public void setUp() throws Exception { 47 converter = makeConverter(); 48 } 49 50 public static TestSuite suite() { 51 return new TestSuite(FileConverterTestCase.class); 52 } 53 54 public void tearDown() throws Exception { 55 converter = null; 56 } 57 58 60 protected Converter makeConverter() { 61 return new FileConverter(); 62 } 63 64 protected Class getExpectedType() { 65 return File .class; 66 } 67 68 70 public void testSimpleConversion() throws Exception { 71 String [] message= { 72 "from String", 73 "from String", 74 "from String" 75 }; 76 77 Object [] input = { 78 "/tmp", 79 "/tmp/foo.txt", 80 "/tmp/does/not/exist.foo" 81 }; 82 83 File [] expected = { 84 new File ("/tmp"), 85 new File ("/tmp/foo.txt"), 86 new File ("/tmp/does/not/exist.foo") 87 }; 88 89 for(int i=0;i<expected.length;i++) { 90 assertEquals(message[i] + " to File",expected[i],converter.convert(File .class,input[i])); 91 assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i])); 92 } 93 } 94 95 } 96 97 | Popular Tags |