### Question:
ConnectionsManager { public Connection openConnection(ConnectionConfiguration configuration) throws ConnectionException { final GetMethod theGetMethod = new GetMethod(configuration.getUri().toString()); theGetMethod.setRequestHeader("User-Agent", "CrawlerViolet"); theGetMethod.setRequestHeader("Accept-Encoding", "gzip, *"); theGetMethod.setFollowRedirects(true); final HttpClient theClient = new HttpClient(this.manager); if (configuration.getCredentials() != null) { theGetMethod.setDoAuthentication(true); final HttpClientParams theParams = new HttpClientParams(DefaultHttpParams.getDefaultParams()); theParams.setAuthenticationPreemptive(true); theParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES); theClient.setParams(theParams); final HttpState theState; if (theClient.getState() != null) { theState = theClient.getState(); theState.clearCredentials(); } else { theState = new HttpState(); } theState.setCredentials(new AuthScope(configuration.getUri().getHost(), AuthScope.ANY_PORT), configuration.getCredentials()); } final String etag = configuration.getEtag(); if (etag != null) { theGetMethod.addRequestHeader("If-None-Match", etag); } final Date lastModified = configuration.getLastModified(); if (lastModified != null) { theGetMethod.addRequestHeader("If-Modified-Since", HttpDateFormat.toString(lastModified)); } try { theClient.executeMethod(theGetMethod); } catch (final Exception e) { ConnectionsManager.LOGGER.fatal(e, e); theGetMethod.releaseConnection(); throw new ConnectionException(e); } if (theGetMethod.getStatusCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { theGetMethod.releaseConnection(); return null; } else if (theGetMethod.getStatusCode() > 200) { theGetMethod.releaseConnection(); throw new ConnectionException(theGetMethod.getStatusCode(), configuration); } return new Connection(theGetMethod); } ConnectionsManager(int connectionsAmount);  ConnectionsManager(int connectionsAmount, int timeout); Connection openConnection(ConnectionConfiguration configuration); void shutdown();  }### Answer:
@Test(expected = ConnectionException.class) public void needsCredentialsTest() throws ConnectionException, URISyntaxException { final String uri = "https: final ConnectionsManager manager = new ConnectionsManager(1); final ConnectionConfiguration configuration = new ConnectionConfiguration(uri); manager.openConnection(configuration); }
@Test(expected = ConnectionException.class) public void withInvalidCredentialsTest() throws ConnectionException, URISyntaxException { final String uri = "https: final ConnectionsManager manager = new ConnectionsManager(1); final ConnectionConfiguration configuration = new ConnectionConfiguration(uri); configuration.addCredentials("vnabaztag", "violet"); manager.openConnection(configuration); }
@Test public void withValidCredentialsTest() throws ConnectionException, IOException, URISyntaxException { final String uri = "https: final ConnectionsManager manager = new ConnectionsManager(1); final ConnectionConfiguration configuration = new ConnectionConfiguration(uri); configuration.addCredentials("vnabaztag", "violet123"); final Connection connection = manager.openConnection(configuration); final byte[] content = IOUtils.toByteArray(connection.getInputStream()); Assert.assertTrue(content.length > 0); }