protected synchronized boolean download(final DownloadableFile downloadableFile) throws IOException, GeneralSecurityException {
        File toDownload = downloadableFile.getLocalFile();
        LOG.info("Downloading {}", toDownload);
        String url = downloadableFile.url(urlGenerator);
        final HttpRequestBase request = new HttpGet(url);
        request.setConfig(RequestConfig.custom().setConnectTimeout(HTTP_TIMEOUT_IN_MILLISECONDS).build());

        try (CloseableHttpClient httpClient = httpClientBuilder.build();
             CloseableHttpResponse response = httpClient.execute(request)) {
            LOG.info("Got server response");
            if (response.getEntity() == null) {
                LOG.error("Unable to read file from the server response");
                return false;
            }
            handleInvalidResponse(response, url);
            try (BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(downloadableFile.getLocalFile()))) {
                response.getEntity().writeTo(outStream);
                LOG.info("Piped the stream to {}", downloadableFile);
            }
        }
        return true;
    }
@Test
    public void shouldReturnFalseIfTheServerDoesNotRespondWithEntity() throws Exception {
        GoAgentServerHttpClientBuilder builder = mock(GoAgentServerHttpClientBuilder.class);
        CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
        when(builder.build()).thenReturn(closeableHttpClient);
        CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
        when(closeableHttpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
        ServerBinaryDownloader downloader = new ServerBinaryDownloader(builder, ServerUrlGeneratorMother.generatorFor("localhost", server.getPort()));
        assertThat(downloader.download(DownloadableFile.AGENT), is(false));
    }