HttpClientExample { public String downloadFileAsString(String url) throws IOException { BrotliLibraryLoader.loadBrotli(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.addInterceptorFirst(httpRequestInterceptor); httpClientBuilder.addInterceptorFirst(httpResponseInterceptor); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { String entity = downloadFileAsString(httpClient, url); if (entity != null) return entity; } return null; }  String downloadFileAsString(String url);  }
@Test public void brotli_downloads_can_be_decompressed_via_apache_httpclient() throws IOException, HttpException { HttpClientExample clientExample = new HttpClientExample(); clientExample.httpResponseInterceptor = spy(clientExample.httpResponseInterceptor); ArgumentCaptor<HttpResponse> httpResponseCaptor = ArgumentCaptor.forClass(HttpResponse.class); doCallRealMethod().when(clientExample.httpResponseInterceptor).process(httpResponseCaptor.capture(), any(HttpContext.class)); String text = clientExample.downloadFileAsString(indexHtmlUrl); assertThat(text).contains("Info-ZIP; Zip, UnZip, gzip and zlib co-author; PNG group"); assertThat(text).contains("<i><b>Audio compression</b></i>"); assertBrotliDecompressionWasUsed(httpResponseCaptor); }