jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject jena git commit: Fix tests for windows usage
Date Wed, 29 Apr 2015 13:43:13 GMT
Repository: jena
Updated Branches:
  refs/heads/master 3aed4b35c -> 366d40b82


Fix tests for windows usage


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/366d40b8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/366d40b8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/366d40b8

Branch: refs/heads/master
Commit: 366d40b8242aa1c1b9abce3cb1be58b67ac426ed
Parents: 3aed4b3
Author: Andy Seaborne <andy@apache.org>
Authored: Wed Apr 29 14:37:37 2015 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed Apr 29 14:37:37 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/atlas/lib/IRILib.java  |   7 +-
 .../jena/atlas/lib/TestFilenameProcessing.java  | 120 +++++++++++--------
 2 files changed, 69 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/366d40b8/jena-base/src/main/java/org/apache/jena/atlas/lib/IRILib.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/IRILib.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/IRILib.java
index daafb74..3884640 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/IRILib.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/IRILib.java
@@ -19,7 +19,7 @@
 package org.apache.jena.atlas.lib;
 
 import java.io.File ;
-import java.io.IOException ;
+import java.nio.file.Paths ;
 
 import org.apache.jena.atlas.AtlasException ;
 import org.apache.jena.base.Sys ;
@@ -127,10 +127,7 @@ public class IRILib
         // No "file:"
         // Make Absolute filename.
         boolean trailingSlash = fn.endsWith("/") ;
-        File file = new File(fn) ;
-        
-        try { fn = file.getCanonicalPath() ; }
-        catch (IOException e) { fn = file.getAbsolutePath() ; }
+        fn = Paths.get(fn).toAbsolutePath().normalize().toString() ;
         
         if ( trailingSlash && ! fn.endsWith("/") )
             fn = fn + "/" ;

http://git-wip-us.apache.org/repos/asf/jena/blob/366d40b8/jena-base/src/test/java/org/apache/jena/atlas/lib/TestFilenameProcessing.java
----------------------------------------------------------------------
diff --git a/jena-base/src/test/java/org/apache/jena/atlas/lib/TestFilenameProcessing.java
b/jena-base/src/test/java/org/apache/jena/atlas/lib/TestFilenameProcessing.java
index 43f9c2f..6f1d493 100644
--- a/jena-base/src/test/java/org/apache/jena/atlas/lib/TestFilenameProcessing.java
+++ b/jena-base/src/test/java/org/apache/jena/atlas/lib/TestFilenameProcessing.java
@@ -26,7 +26,6 @@ import org.junit.Test ;
 
 public class TestFilenameProcessing extends BaseTest
 {
-    // See also TestFunction2 for tests for encode_for_uri
     @Test public void encode_1() { encodeComponent("abc", "abc") ; }
     @Test public void encode_2() { encodeComponent("", "") ; }
     @Test public void encode_3() { encodeComponent(":/", "%3A%2F") ; }
@@ -34,55 +33,54 @@ public class TestFilenameProcessing extends BaseTest
     // ---- Main tests.
     // Portablility
 
-    
+    static boolean isWindows = File.separatorChar != '/' ;
+
     private static String cwd = Paths.get(".").toAbsolutePath().normalize().toString() ;
     // Sort out cwd.
     // Must start "/", must not end "/"
     // Must be /-style, not \
     static {
-        if ( File.separatorChar != '/' ) {
+        if ( isWindows ) {
             // Canonical
             cwd = cwd.replace(File.separatorChar, '/') ;
+            // Drive letters.
+            if ( ! cwd.startsWith("/" ) )
+                cwd = "/" + cwd ;
         }
-        // Drive letters.
-        if ( ! cwd.startsWith("/" ) )
-            cwd = "/" + cwd ;
     }
     
-    @Test public void fileIRI_1()
-    {
-        String uri = testFileIRI("D.ttl") ; 
+    @Test
+    public void fileIRI_1() {
+        String uri = testFileIRI("D.ttl") ;
         assertTrue(uri.endsWith("D.ttl")) ;
     }
-    
-    @Test public void fileIRI_2()
-    {
-        String uri = testFileIRI("file:/D.ttl") ; 
+
+    @Test
+    public void fileIRI_2() {
+        String uri = testFileIRI("file:/D.ttl") ;
         assertTrue(uri.endsWith("D.ttl")) ;
     }
-    
-    @Test public void fileIRI_3()
-    {
-        String uri = testFileIRI("file://D.ttl") ; 
+
+    @Test
+    public void fileIRI_3() {
+        String uri = testFileIRI("file://D.ttl") ;
         assertTrue(uri.endsWith("D.ttl")) ;
     }
 
-    @Test public void fileIRI_4()
-    {
+    @Test
+    public void fileIRI_4() {
         String iri = testFileIRI("file:///D.ttl") ;
-        // Even on windows, this is used as-is so no drive letter. 
+        // Even on windows, this is used as-is so no drive letter.
         assertEquals("file:///D.ttl", iri) ;
     }
-    
-    private static String testFileIRI(String fn)
-    {
+
+    private static String testFileIRI(String fn) {
         String uri1 = IRILib.filenameToIRI(fn) ;
         assertTrue(uri1.startsWith("file:///")) ;
         String uri2 = IRILib.filenameToIRI(uri1) ;
         assertEquals(uri1, uri2) ;
         return uri1 ;
     }
-
     
     @Test
     public void fileURL_1() {
@@ -93,45 +91,65 @@ public class TestFilenameProcessing extends BaseTest
 
     @Test
     public void fileURL_2() {
-        filenameToIRI("/abc", "file:///abc") ;
+        if ( ! isWindows )
+            // Windows inserts a drive letter
+            filenameToIRI("/abc", "file:///abc") ;
     }
     
-    static boolean isWindows = File.pathSeparator.equals(";") ;
-
-    
-    @Test public void fileURL_3()
-    { 
+    @Test
+    public void fileURL_3() {
         if ( isWindows )
-            filenameToIRI("c:/Program File/App File", "file:///c:/Program%20File/App%20File")
; 
+            filenameToIRI("C:/Program File/App File", "file:///C:/Program%20File/App%20File")
;
         else
             filenameToIRI("/Program File/App File", "file:///Program%20File/App%20File")
;
     }
 
-    @Test public void fileURL_4()
-    { 
+    @Test
+    public void fileURL_4() {
         if ( isWindows )
-            filenameToIRI("c:/Program File/App Dir/", "file:///c:/Program%20File/App%20Dir/")
; 
+            filenameToIRI("C:/Program File/App Dir/", "file:///C:/Program%20File/App%20Dir/")
;
         else
             filenameToIRI("/Program File/App Dir/", "file:///Program%20File/App%20Dir/")
;
     }
-    
-    @Test public void fileURL_5()
-    {
+
+    @Test
+    public void fileURL_5() {
         if ( isWindows )
-            filenameToIRI("c:\\Windows\\Path", "file:///c:/Windows/Path") ;
+            filenameToIRI("C:\\Windows\\Path", "file:///C:/Windows/Path") ;
         else
-            filenameToIRI("c:\\Windows\\Path", "file://"+cwd+"/c:%5CWindows%5CPath") ;
-        
+            filenameToIRI("C:\\Windows\\Path", "file://" + cwd + "/C:%5CWindows%5CPath")
;
     }
     
-    @Test public void fileURL_6() { filenameToIRI("~user", "file://"+cwd+"/~user") ; }
-    @Test public void fileURL_7() { filenameToIRI(".", "file://"+cwd) ; }
+    @Test
+    public void fileURL_6() {
+        filenameToIRI("~user", "file://" + cwd + "/~user") ;
+    }
+
+    @Test
+    public void fileURL_7() {
+        filenameToIRI(".", "file://" + cwd) ;
+    }
     
-    @Test public void fileURL_10() { filenameToIRI("file:abc", "file://"+cwd+"/abc" ) ; }
-    @Test public void fileURL_11() { filenameToIRI("file:/abc", "file:///abc" ) ; }
-    @Test public void fileURL_12() { filenameToIRI("file:", "file://"+cwd ) ; }
+    @Test
+    public void fileURL_10() {
+        filenameToIRI("file:abc", "file://" + cwd + "/abc") ;
+    }
+    @Test public void fileURL_11() { 
+        if ( ! isWindows )
+            // Windows inserts a drive letter
+            filenameToIRI("file:/abc", "file:///abc" ) ;
+    }
     
-    @Test public void fileURL_13() { filenameToIRI("file:.", "file://"+cwd+"" ) ; }
+    @Test
+    public void fileURL_12() {
+        filenameToIRI("file:", "file://" + cwd) ;
+    }
+    
+    @Test
+    public void fileURL_13() {
+        filenameToIRI("file:.", "file://" + cwd + "") ;
+    }
+
     @Test public void fileURL_14() {
         String x = cwd ;
         if ( isWindows )
@@ -139,18 +157,14 @@ public class TestFilenameProcessing extends BaseTest
         x = cwd.replaceAll("/[^/]*$", "") ;
         filenameToIRI("file:..", "file://"+x ) ;
     }
-
     
-    private static void encodeComponent(String string, String result)
-    {
+    private static void encodeComponent(String string, String result) {
         String r = IRILib.encodeUriComponent(string) ;
         assertEquals(result, r) ;
     }
-    
-    private static void filenameToIRI(String string, String result)
-    {
+
+    private static void filenameToIRI(String string, String result) {
         String r = IRILib.filenameToIRI(string) ;
         assertEquals(result, r) ;
     }
-    
 }


Mime
View raw message