URLConnection extends java.net.URLConnection { @Override public Map<String, List<String>> getHeaderFields() { try { connect(); } catch (IOException e) { throw new IllegalStateException(e); } final Map<String, List<String>> flds = new HashMap<>(); flds.put(CONTENT_TYPE, singletonList(this.contentType)); flds.put(CONTENT_LENGTH, singletonList(Long.toString(this.file.length()))); flds.put(LAST_MODIFIED, singletonList(Long.toString(this.file.lastModified()))); return flds; } protected  URLConnection(URL url); @Override String getHeaderField(int index); @Override String getHeaderField(String name); @Override String getHeaderFieldKey(int index); @Override Map<String, List<String>> getHeaderFields(); @Override void connect(); @Override OutputStream getOutputStream(); @Override InputStream getInputStream();  }
@Test public void getHeaderFields() { Map<?,?> map = this.connection.getHeaderFields(); assertNotNull(map); assertEquals(3, map.size()); assertEquals(Collections.singletonList("text/plain"), map.get("content-type")); assertEquals(Collections.singletonList("25"), map.get("content-length")); assertNotNull(map.get("last-modified")); assertNull(map.get("expires")); }