### Question:
SystemDefaultCredentialsProvider implements CredentialsStore { @Override public Credentials getCredentials(final AuthScope authScope, final HttpContext context) { Args.notNull(authScope, "Auth scope"); final Credentials localcreds = internal.getCredentials(authScope, context); if (localcreds != null) { return localcreds; } final String host = authScope.getHost(); if (host != null) { final HttpClientContext clientContext = context != null ? HttpClientContext.adapt(context) : null; final String protocol = authScope.getProtocol() != null ? authScope.getProtocol() : (authScope.getPort() == 443 ? URIScheme.HTTPS.id : URIScheme.HTTP.id); PasswordAuthentication systemcreds = getSystemCreds( protocol, authScope, Authenticator.RequestorType.SERVER, clientContext); if (systemcreds == null) { systemcreds = getSystemCreds( protocol, authScope, Authenticator.RequestorType.PROXY, clientContext); } if (systemcreds == null) { systemcreds = getProxyCredentials("http", authScope); if (systemcreds == null) { systemcreds = getProxyCredentials("https", authScope); } } if (systemcreds != null) { final String domain = System.getProperty("http.auth.ntlm.domain"); if (domain != null) { return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain); } if (StandardAuthScheme.NTLM.equalsIgnoreCase(authScope.getSchemeName())) { return new NTCredentials( systemcreds.getUserName(), systemcreds.getPassword(), null, null); } return new UsernamePasswordCredentials(systemcreds.getUserName(), systemcreds.getPassword()); } } return null; } SystemDefaultCredentialsProvider(); @Override void setCredentials(final AuthScope authScope, final Credentials credentials); @Override Credentials getCredentials(final AuthScope authScope, final HttpContext context); @Override void clear();  }### Answer:
@Test public void testSystemCredentialsProviderCredentials() throws Exception { final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1); final URL httpRequestUrl = new URL(TARGET_SCHEME1, TARGET_HOST1, TARGET_PORT1, "/"); final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, StandardAuthScheme.BASIC); final HttpCoreContext coreContext = new HttpCoreContext(); coreContext.setAttribute(HttpCoreContext.HTTP_REQUEST, new HttpGet(httpRequestUrl.toURI())); final Credentials receivedCredentials = new SystemDefaultCredentialsProvider().getCredentials(authScope, coreContext); Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1, PROMPT1, StandardAuthScheme.BASIC, httpRequestUrl, RequestorType.SERVER); Assert.assertNotNull(receivedCredentials); Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName()); Assert.assertEquals(AUTH1.getPassword(), receivedCredentials.getPassword()); }
@Test public void testSystemCredentialsProviderNoContext() throws Exception { final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1); final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, StandardAuthScheme.BASIC); final Credentials receivedCredentials = new SystemDefaultCredentialsProvider().getCredentials(authScope, null); Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1, PROMPT1, StandardAuthScheme.BASIC, null, RequestorType.SERVER); Assert.assertNotNull(receivedCredentials); Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName()); Assert.assertEquals(AUTH1.getPassword(), receivedCredentials.getPassword()); }