ApacheHeaders implements Headers { public Iterator<br.com.caelum.restfulie.http.Header> iterator() { List<br.com.caelum.restfulie.http.Header> headers = new ArrayList<br.com.caelum.restfulie.http.Header>(); for(Header apacheHeader : response.getAllHeaders()) { br.com.caelum.restfulie.http.Header h = new DefaultHeader(apacheHeader.getName(),apacheHeader.getValue()); headers.add(h); } return headers.iterator(); } ApacheHeaders(HttpResponse response, RestClient client); String getMain(String key); List<String> get(String key); String getFirst(String key); List<Link> getLinks(); Link getLink(String rel); Iterator<br.com.caelum.restfulie.http.Header> iterator();  }
@Test public void shouldBeIterable() { when(header.getName()).thenReturn("Accept"); when(header.getValue()).thenReturn("application/xml"); org.apache.http.Header apacheHeader2 = mock(org.apache.http.Header.class); when(apacheHeader2.getName()).thenReturn("Content-type"); when(apacheHeader2.getValue()).thenReturn("application/xml"); when(response.getAllHeaders()).thenReturn(new org.apache.http.Header[] {header,apacheHeader2}); Headers headers = new ApacheHeaders(response,client); for(Header h : headers) { System.out.println(h.getName()); System.out.println(h.getValue()); } Iterator<Header> iterator = headers.iterator(); Header header = iterator.next(); assertThat("Accept", is(equalTo(header.getName()))); assertThat("application/xml", is(equalTo(header.getValue()))); Header header2 = iterator.next(); assertThat("Content-type", is(equalTo(header2.getName()))); assertThat("application/xml", is(equalTo(header2.getValue()))); }