CachingHttpResponse implements ForwardingHttpResponse { @Override public HttpHeaders getHeaders() { return headers.get(); } CachingHttpResponse(final HttpResponse response); @Override HttpResponse delegate(); @Override HttpHeaders getHeaders();  }
@Test void shouldDelegate() { final CachingHttpResponse unit = new CachingHttpResponse(MockHttpResponse.create()); assertThat(unit.getHeaders(), is(anEmptyMap())); }
@Test void shouldCache() { final HttpResponse delegate = mock(HttpResponse.class); when(delegate.getHeaders()).thenReturn(HttpHeaders.empty()); final CachingHttpResponse unit = new CachingHttpResponse(delegate); unit.getHeaders(); unit.getHeaders(); verify(delegate, atMost(1)).getHeaders(); }