URLConnection extends java.net.URLConnection { @Override public String getHeaderField(int index) { assert index >= 0 : AssertMessages.positiveOrZeroParameter(); try { connect(); } catch (IOException e) { throw new IllegalStateException(e); } switch (index) { case 0: return this.contentType; case 1: return Long.toString(this.file.length()); case 2: return Long.toString(this.file.lastModified()); default: } return null; } 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 getHeaderFieldInt() { assertEquals("text/plain", this.connection.getHeaderField(0)); assertEquals("25", this.connection.getHeaderField(1)); assertNotNull(this.connection.getHeaderField(2)); assertNull(this.connection.getHeaderField(3)); }
@Test public void getHeaderFieldString() { assertEquals("text/plain", this.connection.getHeaderField("content-type")); assertEquals("25", this.connection.getHeaderField("content-length")); assertNotNull(this.connection.getHeaderField("last-modified")); assertNull(this.connection.getHeaderField("expires")); }