01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * Test Case for the FileConverter class.
29: *
30: * @author James Strachan
31: * @version $Revision: 438363 $ $Date: 2006-08-30 05:48:00 +0100 (Wed, 30 Aug 2006) $
32: */
33:
34: public class FileConverterTestCase extends TestCase {
35:
36: private Converter converter = null;
37:
38: // ------------------------------------------------------------------------
39:
40: public FileConverterTestCase(String name) {
41: super (name);
42: }
43:
44: // ------------------------------------------------------------------------
45:
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: // ------------------------------------------------------------------------
59:
60: protected Converter makeConverter() {
61: return new FileConverter();
62: }
63:
64: protected Class getExpectedType() {
65: return File.class;
66: }
67:
68: // ------------------------------------------------------------------------
69:
70: public void testSimpleConversion() throws Exception {
71: String[] message = { "from String", "from String",
72: "from String" };
73:
74: Object[] input = { "/tmp", "/tmp/foo.txt",
75: "/tmp/does/not/exist.foo" };
76:
77: File[] expected = { new File("/tmp"), new File("/tmp/foo.txt"),
78: new File("/tmp/does/not/exist.foo") };
79:
80: for (int i = 0; i < expected.length; i++) {
81: assertEquals(message[i] + " to File", expected[i],
82: converter.convert(File.class, input[i]));
83: assertEquals(message[i] + " to null type", expected[i],
84: converter.convert(null, input[i]));
85: }
86: }
87:
88: }
|