MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / localFile

Method localFile

src/test/java/org/htmlunit/WebClient2Test.java:441–461  ·  view source on GitHub ↗

This is supported by reals browsers but not with HtmlUnit. @throws Exception if the test fails

()

Source from the content-addressed store, hash-verified

439 * @throws Exception if the test fails
440 */
441 @Test
442 public void localFile() throws Exception {
443 final URL url = getClass().getClassLoader().getResource("simple.html");
444 String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8);
445 if (file.startsWith("/") && file.contains(":")) {
446 // we have to remove the trailing slash to test the c:\.... case.
447 file = file.substring(1);
448 }
449
450 assertTrue("File '" + file + "' does not exist", new File(file).exists());
451
452 try (WebClient webClient = new WebClient(getBrowserVersion())) {
453 webClient.getPage(file);
454 fail("IOException expected");
455 }
456 catch (final IOException e) {
457 assertTrue(e.getMessage(),
458 e.getMessage().startsWith("Unsupported protocol '")
459 || e.getMessage().startsWith("no protocol: /"));
460 }
461 }
462
463 /**
464 * @throws Exception if the test fails

Callers

nothing calls this directly

Calls 10

getFileMethod · 0.80
substringMethod · 0.80
assertTrueMethod · 0.80
getMessageMethod · 0.80
containsMethod · 0.65
getPageMethod · 0.65
getClassMethod · 0.45
decodeMethod · 0.45
startsWithMethod · 0.45
getBrowserVersionMethod · 0.45

Tested by

no test coverage detected