public void testCredentialsMatching() {
Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");
Credentials creds3 = new UsernamePasswordCredentials("name3", "pass3");
AuthScope scope1 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
AuthScope scope2 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm");
AuthScope scope3 = new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM);
BasicCredentialsProvider state = new BasicCredentialsProvider();
state.setCredentials(scope1, creds1);
state.setCredentials(scope2, creds2);
state.setCredentials(scope3, creds3);
Credentials got = state.getCredentials(
new AuthScope("someotherhost", 80, "someotherrealm", "basic"));
Credentials expected = creds1;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("someotherhost", 80, "somerealm", "basic"));
expected = creds2;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("somehost", 80, "someotherrealm", "basic"));
expected = creds3;
assertEquals(expected, got);
}