@Test
  public void headers() throws IOException {
    byte[] bytes = {1, 2, 3};
    Files.write(path, bytes);
    FileTime lastModified = Files.getLastModifiedTime(path);

    URL url = path.toUri().toURL();
    URLConnection conn = url.openConnection();

    // read header fields directly
    assertThat(conn.getHeaderFields()).containsEntry("content-length", ImmutableList.of("3"));
    assertThat(conn.getHeaderFields())
        .containsEntry("content-type", ImmutableList.of("application/octet-stream"));

    if (lastModified != null) {
      assertThat(conn.getHeaderFields()).containsKey("last-modified");
      assertThat(conn.getHeaderFields()).hasSize(3);
    } else {
      assertThat(conn.getHeaderFields()).hasSize(2);
    }

    // use the specific methods for reading the expected headers
    assertThat(conn.getContentLengthLong()).isEqualTo(Files.size(path));
    assertThat(conn.getContentType()).isEqualTo("application/octet-stream");

    if (lastModified != null) {
      // The HTTP date format does not include milliseconds, which means that the last modified time
      // returned from the connection may not be exactly the same as that of the file system itself.
      // The difference should less than 1000ms though, and should never be greater.
      long difference = lastModified.toMillis() - conn.getLastModified();
      assertThat(difference).isIn(Range.closedOpen(0L, 1000L));
    } else {
      assertThat(conn.getLastModified()).isEqualTo(0L);
    }
  }
Tests that {@link URL} instances can be created and used from jimfs URIs.

@author Colin Decker
jimfs/src/test/java/com/google/common/jimfs/UrlTest.java