KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > beanutils > converters > FileConverterTestCase


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.beanutils.converters;
18
19 import java.io.File JavaDoc;
20
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24 import org.apache.commons.beanutils.Converter;
25
26
27 /**
28  * Test Case for the FileConverter class.
29  *
30  * @author James Strachan
31  * @version $Revision: 1.4 $ $Date: 2004/02/28 13:18:37 $
32  */

33
34 public class FileConverterTestCase extends TestCase {
35
36     private Converter converter = null;
37
38     // ------------------------------------------------------------------------
39

40     public FileConverterTestCase(String JavaDoc name) {
41         super(name);
42     }
43     
44     // ------------------------------------------------------------------------
45

46     public void setUp() throws Exception JavaDoc {
47         converter = makeConverter();
48     }
49
50     public static TestSuite suite() {
51         return new TestSuite(FileConverterTestCase.class);
52     }
53
54     public void tearDown() throws Exception JavaDoc {
55         converter = null;
56     }
57
58     // ------------------------------------------------------------------------
59

60     protected Converter makeConverter() {
61         return new FileConverter();
62     }
63     
64     protected Class JavaDoc getExpectedType() {
65         return File JavaDoc.class;
66     }
67
68     // ------------------------------------------------------------------------
69

70     public void testSimpleConversion() throws Exception JavaDoc {
71         String JavaDoc[] message= {
72             "from String",
73             "from String",
74             "from String"
75         };
76         
77         Object JavaDoc[] input = {
78             "/tmp",
79             "/tmp/foo.txt",
80             "/tmp/does/not/exist.foo"
81         };
82         
83         File JavaDoc[] expected = {
84             new File JavaDoc("/tmp"),
85             new File JavaDoc("/tmp/foo.txt"),
86             new File JavaDoc("/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 JavaDoc.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