001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.beanutils.converters;
019:
020: import junit.framework.TestSuite;
021: import junit.framework.TestCase;
022:
023: import org.apache.commons.beanutils.Converter;
024:
025: import java.net.URL;
026:
027: /**
028: * Test Case for the URLConverter class.
029: *
030: * @version $Revision: 471628 $ $Date: 2006-11-06 04:06:45 +0000 (Mon, 06 Nov 2006) $
031: */
032:
033: public class URLConverterTestCase extends TestCase {
034:
035: private Converter converter = null;
036:
037: // ------------------------------------------------------------------------
038:
039: public URLConverterTestCase(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(URLConverterTestCase.class);
051: }
052:
053: public void tearDown() throws Exception {
054: converter = null;
055: }
056:
057: // ------------------------------------------------------------------------
058:
059: protected Converter makeConverter() {
060: return new URLConverter();
061: }
062:
063: protected Class getExpectedType() {
064: return URL.class;
065: }
066:
067: // ------------------------------------------------------------------------
068:
069: public void testSimpleConversion() throws Exception {
070: String[] message = { "from String", "from String",
071: "from String", "from String", "from String",
072: "from String", "from String", "from String", };
073:
074: Object[] input = { "http://www.apache.org",
075: "http://www.apache.org/", "ftp://cvs.apache.org",
076: "file://project.xml", "http://208.185.179.12",
077: "http://www.apache.org:9999/test/thing",
078: "http://user:admin@www.apache.org:50/one/two.three",
079: "http://notreal.apache.org", };
080:
081: URL[] expected = {
082: new URL("http://www.apache.org"),
083: new URL("http://www.apache.org/"),
084: new URL("ftp://cvs.apache.org"),
085: new URL("file://project.xml"),
086: new URL("http://208.185.179.12"),
087: new URL("http://www.apache.org:9999/test/thing"),
088: new URL(
089: "http://user:admin@www.apache.org:50/one/two.three"),
090: new URL("http://notreal.apache.org") };
091:
092: for (int i = 0; i < expected.length; i++) {
093: assertEquals(message[i] + " to URL", expected[i], converter
094: .convert(URL.class, input[i]));
095: assertEquals(message[i] + " to null type", expected[i],
096: converter.convert(null, input[i]));
097: }
098:
099: for (int i = 0; i < expected.length; i++) {
100: assertEquals(input[i] + " to String", input[i], converter
101: .convert(String.class, expected[i]));
102: }
103: }
104:
105: }
|