You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/03/31 08:34:50 UTC

[GitHub] [netbeans] mbien commented on a change in pull request #3902: improved tests for BaseUtilities.toFile & BaseUtitities.toURI

mbien commented on a change in pull request #3902:
URL: https://github.com/apache/netbeans/pull/3902#discussion_r839328422



##########
File path: platform/openide.util/test/unit/src/org/openide/util/BaseUtilitiesTest.java
##########
@@ -111,31 +112,106 @@ public void testIsJavaIdentifier() throws Exception {
         assertFalse(BaseUtilities.isJavaIdentifier("some.thing"));
     }
 
-    public void testFileURI() throws Exception {
-        if (BaseUtilities.isWindows()) {
-            assertFileURI("C:\\some\\path #1", "file:/C:/some/path%20%231");
-            assertEquals(new File("C:\\some\\path"), BaseUtilities.toFile(new URI("file:/C:/some/path")));
-            assertEquals(new File("C:\\some\\path"), BaseUtilities.toFile(new URI("file:///C:/some/path")));
-            assertEquals(new File("C:\\some\\path"), BaseUtilities.toFile(new URI("file:/C:/some/path/")));
-            assertFileURI("\\\\server\\share\\path", "file://server/share/path");
-            assertEquals(new File("\\\\server\\share\\path"), BaseUtilities.toFile(new URI("file:////server/share/path")));
-            assertEquals(new File("\\\\server\\share\\path #1"), BaseUtilities.toFile(new URI("file:////server/share/path%20%231")));
-        } else {
-            assertFileURI("/some/path #1", "file:/some/path%20%231");
-            assertEquals(new File("/some/path"), BaseUtilities.toFile(new URI("file:/some/path")));
-            assertEquals(new File("/some/path"), BaseUtilities.toFile(new URI("file:///some/path")));
-            assertEquals(new File("/some/path"), BaseUtilities.toFile(new URI("file:/some/path/")));
+    //--------------------------------------------------------------------------
+    public void test_toFile_throwsNullPonter_whenArgumentIsNull()
+            throws Exception {
+
+        try {
+            toFile(null);
+            fail();
+        } catch (final NullPointerException e) {
+            return;
+        }
+    }
+    
+    //--------------------------------------------------------------------------
+    public void test_toFile_throwsIllegalArgument_whenGivenNonFileURI()
+            throws Exception {
+
+        try {
+            toFile(new URI("http://example.com"));
+            fail();
+        } catch (final IllegalArgumentException e) {
+            return;
+        }
+        try {
+            toFile(new URI("mailto:person@example.com"));
+            fail();
+        } catch (final IllegalArgumentException e) {
+            return;
+        }
+        try {
+            toFile(new URI("isbn:12345"));
+            fail();
+        } catch (final IllegalArgumentException e) {
+            return;
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    public void test_toFile_returnsFile_whenGivenUnixPath()
+            throws Exception {
+
+        assertEquals(new File("/some/path"), toFile(new URI("file:/some/path")));
+        assertEquals(new File("/some/path"), toFile(new URI("file:///some/path")));
+        assertEquals(new File("/some/path"), toFile(new URI("file:/some/path/")));
+        assertEquals(new File("/some/path #1"), toFile(new URI("file:/some/path%20%231")));
+    }
+
+    //--------------------------------------------------------------------------
+    public void test_toFile_returnsFile_whenGivenWindowsPath()
+            throws Exception {
+
+        if (isWindows()) {
+            assertEquals(new File("C:\\some\\path #1"), toFile(new URI("file:/C:/some/path%20%231")));
+            assertEquals(new File("C:\\some\\path"), toFile(new URI("file:/C:/some/path")));
+            assertEquals(new File("C:\\some\\path"), toFile(new URI("file:///C:/some/path")));
+            assertEquals(new File("C:\\some\\path"), toFile(new URI("file:/C:/some/path/")));
+            assertEquals(new File("\\\\server\\share\\path"), toFile(new URI("file://server/share/path")));
+            assertEquals(new File("\\\\server\\share\\path"), toFile(new URI("file:////server/share/path")));
+            assertEquals(new File("\\\\server\\share\\path #1"), toFile(new URI("file:////server/share/path%20%231")));
+        }
+    }

Review comment:
       I am not a big fan of splitting test cases on a per-OS basis. This would have the effect of getting green badges due to the no-op on half of the tests without having anything tested.
   
   However, looking at what is actually being tested here, I have to wonder if we could just test everything on all systems. There are no files created anyway, the utility is about paths and URIs. Lets try to remove `isWindows()`/`isUnix()` and check if everything works.
   
   If it doesn't and the os-checks were there for a reason, I would prefer that you revert to os independent test cases.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists