/*
 * Copyright (c) 2013 Philipp Meinen <philipp@bind.ch>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software
 * is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
 * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package ch.bind.philib.net;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

import java.io.IOException;
import java.net.URL;

import org.testng.annotations.Test;

public class URLsTest {

    @Test
    public void forClasspathResource() {
        URL a = URLs.forClasspathResource("/words_en");
        URL b = URLs.forClasspathResource("missing");
        assertNotNull(a);
        assertNull(b);
    }

    @Test
    public void forFile() throws IOException {
        URL a = URLs.forFile("foo"); // relative
        URL b = URLs.forFile("/bar"); // absolute

        String workDir = System.getProperty("user.dir");
        assertEquals(a.toString(), "file:" + workDir + "/foo");

        assertEquals(b.toExternalForm(), "file:/bar");
    }
}

@@ -1413,30 +1413,24 @@
 Test %7B%0A%0A
-    
+%09
 @Test%0A
-    
+%09
 public v
@@ -1458,24 +1458,18 @@
 rce() %7B%0A
-        
+%09%09
 URL a = 
@@ -1508,24 +1508,18 @@
 s_en%22);%0A
-        
+%09%09
 URL b = 
@@ -1552,32 +1552,26 @@
 %22missing%22);%0A
-        
+%09%09
 assertNotNul
@@ -1576,24 +1576,18 @@
 ull(a);%0A
-        
+%09%09
 assertNu
@@ -1597,29 +1597,59 @@
 b);%0A
-    %7D%0A%0A    @Test%0A    
+%09%7D%0A%0A%09// platform dependent%0A%09@Test(enabled= false)%0A%09
 publ
@@ -1687,24 +1687,18 @@
 ption %7B%0A
-        
+%09%09
 URL a = 
@@ -1730,24 +1730,18 @@
 elative%0A
-        
+%09%09
 URL b = 
@@ -1775,24 +1775,18 @@
 solute%0A%0A
-        
+%09%09
 String w
@@ -1826,24 +1826,125 @@
 .dir%22);%0A
-        
+//%09%09workDir = workDir.replace('%5C%5C', '/');%0A//%09%09workDir = workDir.startsWith(%22/%22) ? workDir : %22/%22 + workDir;%0A%09%09
 assertEq
@@ -1996,16 +1996,10 @@
 );%0A%0A
-        
+%09%09
 asse
@@ -2045,12 +2045,9 @@
 %22);%0A
-    
+%09
 %7D%0A%7D%0A

disable platform dependent unit test