HttpRequestWrapperWithModifiableHeaders extends HttpRequestWrapper { @Override public HttpHeaders getHeaders() { return modifiableHeaders; } HttpRequestWrapperWithModifiableHeaders(HttpRequest request); @Override HttpHeaders getHeaders();  }
@Test public void constructor_sets_modifiableHeaders_to_a_mutable_copy_of_given_request_headers() { HttpHeaders immutableHeaders = generateImmutableHeaders( MapBuilder.builder("foo", singletonList(UUID.randomUUID().toString())) .put("bar", Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString())) .build() ); doReturn(immutableHeaders).when(requestMock).getHeaders(); verifyImmutableHeaders(immutableHeaders); HttpRequestWrapperWithModifiableHeaders wrapper = new HttpRequestWrapperWithModifiableHeaders(requestMock); verify(requestMock).getHeaders(); HttpHeaders wrapperHeaders = wrapper.getHeaders(); assertThat(wrapperHeaders).isSameAs(wrapper.modifiableHeaders); verifyNoMoreInteractions(requestMock); assertThat(wrapperHeaders).isEqualTo(immutableHeaders); verifyMutableHeaders(wrapperHeaders); }
@Test public void verify_non_header_wrapper_methods_pass_through_to_original_request() { doReturn(new HttpHeaders()).when(requestMock).getHeaders(); HttpRequestWrapperWithModifiableHeaders wrapper = new HttpRequestWrapperWithModifiableHeaders(requestMock); HttpRequest wrappedRequest = wrapper.getRequest(); URI wrapperUri = wrapper.getURI(); HttpMethod wrapperMethod = wrapper.getMethod(); assertThat(wrappedRequest).isSameAs(requestMock); assertThat(wrapperUri).isSameAs(uri); assertThat(wrapperMethod).isSameAs(wrapperMethod); verify(requestMock).getURI(); verify(requestMock).getMethod(); }