KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > io > junit > IOUtilsTests


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------
28  * IOUtilsTests.java
29  * -----------------
30  * (C)opyright 2003-2005, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: IOUtilsTests.java,v 1.4 2005/10/18 13:16:15 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Jan-2004 : Initial version
40  *
41  */

42
43 package org.jfree.io.junit;
44
45 import java.io.IOException JavaDoc;
46 import java.net.URL JavaDoc;
47
48 import junit.framework.Test;
49 import junit.framework.TestCase;
50 import junit.framework.TestSuite;
51
52 import org.jfree.io.IOUtils;
53
54 /**
55  * Creates a new test case.
56  */

57 public class IOUtilsTests extends TestCase {
58
59     /**
60      * Returns the tests as a test suite.
61      *
62      * @return The test suite.
63      */

64     public static Test suite() {
65         return new TestSuite(IOUtilsTests.class);
66     }
67
68     /**
69      * Constructs a new set of tests.
70      */

71     public IOUtilsTests() {
72         super();
73     }
74
75     /**
76      * Constructs a new set of tests.
77      *
78      * @param name the name of the tests.
79      */

80     public IOUtilsTests(final String JavaDoc name) {
81         super(name);
82     }
83
84     /**
85      * A test for the createRelativeURL() method.
86      *
87      * @throws IOException if there is an I/O problem.
88      */

89     public void testCreateRelativeURL() throws IOException JavaDoc {
90         final URL JavaDoc baseurl = new URL JavaDoc
91             ("http://test.com:80/test/a/funny/directory/basefile.xml");
92
93         final URL JavaDoc testInput1 = new URL JavaDoc ("http://test.com:80/test/a/funny/directory/datafile.jpg");
94         String JavaDoc result = IOUtils.getInstance().createRelativeURL(testInput1, baseurl);
95         assertEquals("datafile.jpg", result);
96         assertEquals(testInput1, new URL JavaDoc (baseurl, result));
97
98         final URL JavaDoc testInput2 = new URL JavaDoc ("http://test.com:80/test/adatafile.jpg");
99         result = IOUtils.getInstance().createRelativeURL(testInput2, baseurl);
100         assertEquals("../../../adatafile.jpg", result);
101         assertEquals(testInput2, new URL JavaDoc (baseurl, result));
102
103         final URL JavaDoc testInput3 = new URL JavaDoc ("http://test.com:80/test/adatafile.jpg?query=test");
104         result = IOUtils.getInstance().createRelativeURL(testInput3, baseurl);
105         assertEquals("../../../adatafile.jpg?query=test", result);
106         assertEquals(testInput3, new URL JavaDoc (baseurl, result));
107     }
108     
109 }
110
Popular Tags