### Question:
StreamingContentSizeFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { final String contentLength = responseContext.getHeaderString(X_CONTENT_LENGTH); if (contentLength != null) { responseContext.getHeaders().remove(HttpHeaders.TRANSFER_ENCODING); responseContext.getHeaders().remove(X_CONTENT_LENGTH); responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, contentLength); } } @Inject  StreamingContentSizeFilter(); @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext); static final String X_CONTENT_LENGTH; }### Answer:
@Test void testNoContentLength() { filter.filter(null, context); Mockito.verify(context, Mockito.never()).getHeaders(); }
@Test void testHeaderModification() { MultivaluedMap<String, String> headers = new MultivaluedHashMap<>(); headers.add(HttpHeaders.TRANSFER_ENCODING, "nothing"); headers.add(X_CONTENT_LENGTH, "nothing"); Mockito.when(context.getHeaderString(X_CONTENT_LENGTH)).thenReturn("this is the length"); Mockito.when(context.getHeaders()).thenAnswer(answer -> headers); filter.filter(null, context); Mockito.verify(context, Mockito.times(3)).getHeaders(); assertAll(() -> assertNull(headers.get(HttpHeaders.TRANSFER_ENCODING), "Should not have transfer encoding"), () -> assertNull(headers.get(X_CONTENT_LENGTH), "Should not have custom content length"), () -> assertEquals("this is the length", headers.getFirst(HttpHeaders.CONTENT_LENGTH), "Should have new content length")); }