mbien commented on a change in pull request #3902:
URL: https://github.com/apache/netbeans/pull/3902#discussion_r841003604
##########
File path:
platform/openide.util/test/unit/src/org/openide/util/BaseUtilitiesTest.java
##########
@@ -111,36 +112,104 @@ 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) {
+ //good
+ }
+ }
+
+
//--------------------------------------------------------------------------
+ public void test_toFile_throwsIllegalArgument_whenGivenNonFileURI()
+ throws Exception {
+
+ try {
+ toFile(new URI("http://example.com"));
+ fail();
+ } catch (final IllegalArgumentException e) {
+ //good
+ }
+ try {
+ toFile(new URI("mailto:[email protected]"));
+ fail();
+ } catch (final IllegalArgumentException e) {
+ //good
+ }
+ try {
+ toFile(new URI("isbn:12345"));
+ fail();
+ } catch (final IllegalArgumentException e) {
+ //good
+ }
+ }
+
//--------------------------------------------------------------------------
+ public void
test_toFile_throwsIllegalArgument_whenGivenFileURIWithIllegalCharacter()
+ throws Exception {
+
+ try {
+ toFile(new URI("file:/C:/some/?"));
+ fail();
+ } catch (final IllegalArgumentException e) {
+ //good
+ }
+ }
+
+
//--------------------------------------------------------------------------
+ public void test_toFile_returnsFile_whenGivenCorrectURI()
+ throws Exception {
+
+ // unix
+ 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")));
+
+ //windows
+ 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")));
+ }
+
+
//--------------------------------------------------------------------------
+ public void test_toURI_throwsNullPonter_whenArgumentIsNull()
+ throws Exception {
+
+ try {
+ toURI(null);
+ fail();
+ } catch (final NullPointerException e) {
+ //good
+ }
+ }
+
+
//--------------------------------------------------------------------------
+ public void test_toURI_returnsURI_whenGivenCorrectPath()
+ throws Exception {
+
+ if (isUnix()) {
+ assertEquals(new URI("file:/some/path"), toURI(new
File("/some/path")));
+ assertEquals(new URI("file:///some/path"), toURI(new
File("/some/path")));
+ assertEquals(new URI("file:/some/path"), toURI(new
File("/some/path/")));
+ assertEquals(new URI("file:/some/path%20%231"), toURI(new
File("/some/path #1")));
+ }
+ if (isWindows()) {
+ assertEquals(new URI("file:/C:/some/path%20%231"), toURI(new
File("C:\\some\\path #1")));
+ assertEquals(new URI("file:/C:/some/path"), toURI(new
File("C:\\some\\path")));
+ assertEquals(new URI("file:///C:/some/path"), toURI(new
File("C:\\some\\path")));
+ assertEquals(new URI("file:/C:/some/path"), toURI(new
File("C:\\some\\path\\")));
+ assertEquals(new URI("file://server/share/path"), toURI(new
File("\\\\server\\share\\path")));
+ assertEquals(new URI("file://server/share/path"), toURI(new
File("\\\\server\\share\\path\\")));
+ assertEquals(new URI("file://server/share/path%20%231"), toURI(new
File("\\\\server\\share\\path #1")));
}
- String s = BaseUtilities.toURI(getWorkDir()).toString();
- assertTrue(s, s.endsWith("/"));
- URI jar = BaseUtilities.toURI(new File(getWorkDir(), "some.jar"));
- URI jarN = jar.resolve("some.jar");
- assertEquals(jar, jarN);
- URI jarR = new URI("jar:" + jar + "!/");
- URI jarNR = new URI("jar:" + jarN + "!/");
- assertEquals("#214131: equal even when wrapped", jarR, jarNR);
Review comment:
awesome
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists