Source:
<code>public void testUrlToFile() throws Exception { handleFile(System.getProperty("user.home")); handleFile(System.getProperty("user.dir")); if (URLs.IS_WINDOWS_OS) { handleFile("C:\\"); handleFile("C:\\one"); handleFile("C:\\one\\two"); handleFile("C:\\one\\two\\and three"); handleFile("D:\\"); assertURL("\\one", "file:/one"); assertURL("\\.\\one", "file:/./one"); assertURL("one", "file://one"); assertURL("./one", "file://./one"); handleFile("\\\\host\\share\\file"); URL url = new URL("file", " File windowsShareFile = URLs.urlToFile(url); assertNotNull(windowsShareFile); } else { handleFile("/one"); handleFile("one"); handleFile("/one/two/and three"); handleFile("/hello world/this++().file"); } assertURL("one", "file:one"); assertURL("/one", "file:/ assertURL(replaceSlashes("C:\\"), "file://C:/"); assertURL(replaceSlashes("C:\\one"), "file://C:/one"); assertURL(replaceSlashes("C:\\one\\two"), "file://C:/one/two"); assertURL(replaceSlashes("C:\\one\\two\\and three"), "file://C:/one/two/and three"); assertEquals("sample", URLs.urlToFile(new URL("file:sample?query")).toString()); assertEquals("sample", URLs.urlToFile(new URL("file:sample#ref")).toString()); File file = File.createTempFile("hello", "world"); handleFile(file.getAbsolutePath()); handleFile(file.getPath()); URL url = new URL("file", " File windowsShareFile = URLs.urlToFile(url); assertNotNull(windowsShareFile); <START> assertEquals("file café", URLs.urlToFile(new URL("file:file%20caf%C3%A9")).toString()); <END> }</code><technical_language>Test case is a bit sparse, adequate. For completeness, testing of better, bit is OK as-is: file:file%20caf%C3%A9" file:/file%20caf%C3%A9" file://file%20caf%C3%A9"</technical_language>

Target:
public void testUrlToFile() throws Exception { handleFile(System.getProperty("user.home")); handleFile(System.getProperty("user.dir")); if (URLs.IS_WINDOWS_OS) { handleFile("C:\\"); handleFile("C:\\one"); handleFile("C:\\one\\two"); handleFile("C:\\one\\two\\and three"); handleFile("D:\\"); assertURL("\\one", "file:/one"); assertURL("\\.\\one", "file:/./one"); assertURL("one", "file://one"); assertURL("./one", "file://./one"); handleFile("\\\\host\\share\\file"); URL url = new URL("file", " File windowsShareFile = URLs.urlToFile(url); assertNotNull(windowsShareFile); } else { handleFile("/one"); handleFile("one"); handleFile("/one/two/and three"); handleFile("/hello world/this++().file"); } assertURL("one", "file:one"); assertURL("/one", "file:/ assertURL(replaceSlashes("C:\\"), "file://C:/"); assertURL(replaceSlashes("C:\\one"), "file://C:/one"); assertURL(replaceSlashes("C:\\one\\two"), "file://C:/one/two"); assertURL(replaceSlashes("C:\\one\\two\\and three"), "file://C:/one/two/and three"); assertEquals("sample", URLs.urlToFile(new URL("file:sample?query")).toString()); assertEquals("sample", URLs.urlToFile(new URL("file:sample#ref")).toString()); File file = File.createTempFile("hello", "world"); handleFile(file.getAbsolutePath()); handleFile(file.getPath()); URL url = new URL("file", " File windowsShareFile = URLs.urlToFile(url); assertNotNull(windowsShareFile); assertEquals("file café", URLs.urlToFile(new URL("file:file%20caf%C3%A9")).toString()); assertEquals("/file café", URLs.urlToFile(new URL("file:/file%20caf%C3%A9")).toString()); assertEquals("file café", URLs.urlToFile(new URL("file://file%20caf%C3%A9")).toString()); }