/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.harmony.luni.tests.java.net;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;

import org.apache.harmony.luni.internal.net.www.protocol.jar.Handler;

import junit.framework.TestCase;

import tests.support.Support_Configuration;
import tests.support.resource.Support_Resources;

/**
 *  Depends on:
 *    file://<basedir>/src/test/resources/org/apache/harmony/luni/tests/java/net/lf.jar
 */
public class URLClassLoaderImplTest extends TestCase {
    
    private static final char SEP = File.separatorChar;
    private static final URL BASE = URLClassLoaderImplTest.class.getClassLoader().getResource(".."+SEP+URLClassLoaderImplTest.class.getPackage().getName().replace('.', SEP));

    /**
     * @tests java.net.URLClassLoader#URLClassLoader(java.net.URL[],
     *        java.lang.ClassLoader, java.net.URLStreamHandlerFactory)
     */
    public void test_Constructor$Ljava_net_URLLjava_lang_ClassLoaderLjava_net_URLStreamHandlerFactory() {
        class TestFactory implements URLStreamHandlerFactory {
            public URLStreamHandler createURLStreamHandler(String protocol) {
                if ("jar".equals(protocol)) {
                    return new Handler();
                } else {
                    fail("Should be jar Handler. But " + protocol);
                    return null;
                }
            }

        }

        URLClassLoader ucl = null;

        URL[] u = new URL[1];
        try {
            u[0] = new URL(BASE.toString() + SEP + "lf.jar");
            ucl = new URLClassLoader(u, null, new TestFactory());
            URL res = null;
            res = ucl.findResource("swt.dll");

            assertNotNull(res);
            assertEquals("Failed", BASE.toString()+SEP+"lf.jar!"+SEP+"swt.dll", res.getFile());
        } catch (MalformedURLException e) {
            fail("should not be here. " + e);
        }
    }

}

@@ -872,54 +872,15 @@
 ava.
-io.File;%0Aimport java.net.MalformedURLException
+net.URI
 ;%0Aim
@@ -1006,16 +1006,50 @@
 ctory;%0A%0A
+import junit.framework.TestCase;%0A%0A
 import o
@@ -1115,143 +1115,14 @@
 r;%0A%0A
-import junit.framework.TestCase;%0A%0Aimport tests.support.Support_Configuration;%0Aimport tests.support.resource.Support_Resources;%0A%0A
 /**%0A *
- 
  Dep
@@ -1129,22 +1129,16 @@
 ends on:
-%0A *   
  file://
@@ -1274,244 +1274,8 @@
 se %7B
-%0A    %0A    private static final char SEP = File.separatorChar;%0A    private static final URL BASE = URLClassLoaderImplTest.class.getClassLoader().getResource(%22..%22+SEP+URLClassLoaderImplTest.class.getPackage().getName().replace('.', SEP));
 %0A%0A  
@@ -1352,22 +1352,8 @@
 L%5B%5D,
-%0A     *       
  jav
@@ -1371,16 +1371,30 @@
 sLoader,
+%0A     *       
  java.ne
@@ -1531,16 +1531,45 @@
 actory()
+%0A            throws Exception
  %7B%0A     
@@ -1813,20 +1813,10 @@
    %7D
- else %7B%0A    
+%0A%0A
     
@@ -1883,36 +1883,32 @@
                 
-    
 return null;%0A   
@@ -1904,34 +1904,16 @@
 n null;%0A
-                %7D%0A
         
@@ -1910,33 +1910,32 @@
 ;%0A            %7D%0A
-%0A
         %7D%0A%0A     
@@ -1941,33 +1941,57 @@
     
-URLClassLoader ucl = null
+final URL base = getClass().getResource(%22lf.jar%22)
 ;%0A%0A 
@@ -2001,117 +2001,65 @@
     
+final 
 URL%5B%5D u
- = new URL%5B1%5D;%0A        try %7B%0A            u%5B0%5D = new URL(BASE.toString() + SEP + %22lf.jar%22);%0A           
+rls = %7B base %7D;%0A        final URLClassLoader
  ucl
@@ -2081,16 +2081,19 @@
 Loader(u
+rls
 , null, 
@@ -2112,27 +2112,25 @@
 ory());%0A
-   
+%0A
         
  URL res
@@ -2121,16 +2121,21 @@
         
+final
  URL res
@@ -2140,32 +2140,8 @@
 es =
- null;%0A            res =
  ucl
@@ -2166,25 +2166,24 @@
 .dll%22);%0A
-%0A
         
     asse
@@ -2170,28 +2170,24 @@
 %22);%0A        
-    
 assertNotNul
@@ -2194,24 +2194,25 @@
 l(res);%0A
+%0A
         
     asse
@@ -2207,195 +2207,139 @@
     
-    assertEquals(%22Failed%22, BASE.toString()+SEP+%22lf.jar!%22+SEP+%22swt.dll%22, res.getFile());%0A        %7D catch (MalformedURLException e) %7B%0A            fail(%22should not be here. %22 + e);%0A        %7D
+final URI e = new URI(%22jar:%22 + base.toExternalForm() + %22!/swt.dll%22);%0A        final URI a = res.toURI();%0A        assertEquals(e, a);
 %0A   

Clean up test and make it more portable (work on windows) Related to HARMONY-6059 - [classlib][luni] jar URL is created with wrong protocol for URLStreamHandler