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