001: /*
002: * @(#)UrlClassLoaderJDK12UTest.java 0.9.0 23-May-2001 - 14:40
003: *
004: * Copyright (C) 2001,2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.util.classes.v1.jdk2;
028:
029: import net.sourceforge.groboutils.util.classes.v1.*;
030: import net.sourceforge.groboutils.junit.v1.iftc.*;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: import java.net.URL;
036:
037: /**
038: * Just like util.http.tests, this uses the Sourceforge account to ensure
039: * that the URLs work correctly. It loads the sample applet "BeliefOfTheDay"
040: * to make sure that this is able to load classes remotely.
041: * As insurance, this also tests to make sure that the same applet is not
042: * in the current classpath.
043: *
044: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
045: * @version $Date: 2003/05/06 05:35:01 $
046: * @since May 23, 2001
047: */
048: public class UrlClassLoaderJDK12UTest extends TestCase {
049: private static final Class THIS_CLASS = UrlClassLoaderJDK12UTest.class;
050:
051: public UrlClassLoaderJDK12UTest(String name) {
052: super (name);
053: }
054:
055: public static Test suite() {
056: InterfaceTestSuite suite = IUrlClassLoaderUTestI.suite();
057: suite.addTestSuite(THIS_CLASS);
058: suite.addFactory(new CxFactory("A") {
059: public Object createImplObject() {
060: return createLoader();
061: }
062: });
063:
064: return suite;
065: }
066:
067: public static void main(String[] args) {
068: String[] name = { THIS_CLASS.getName() };
069:
070: // junit.textui.TestRunner.main( name );
071: // junit.swingui.TestRunner.main( name );
072:
073: junit.textui.TestRunner.main(name);
074: }
075:
076: protected void setUp() throws Exception {
077: super .setUp();
078:
079: // set ourself up
080: }
081:
082: protected void tearDown() throws Exception {
083: // tear ourself down
084:
085: super .tearDown();
086: }
087:
088: protected static UrlClassLoader createLoader() {
089: return new UrlClassLoader();
090: }
091:
092: //---------------------------------------
093: // Super class has many base tests
094:
095: public void testConvertUrl1() {
096: assertNull("returned URL must be null.", createLoader()
097: .convertUrl(null));
098: }
099:
100: public void testConvertUrl2() {
101: URL url = createLoader().convertUrl("http://yo.mama");
102: assertNotNull("convertURL returned null.", url);
103: // JDK 1.2 adds an extra '/' to the end of the URL
104: if (!url.toString().equals("http://yo.mama")
105: && !url.toString().equals("http://yo.mama/")) {
106: fail("convertURL did not format right: it returned '"
107: + url.toString() + "'");
108: }
109: }
110:
111: public void testConvertUrl3() {
112: URL url = createLoader().convertUrl("afile.txt");
113: assertNotNull("convertURL returned null.", url);
114: assertEquals("convertURL did not format right.",
115: url.toString(), "file:afile.txt");
116: }
117: }
|