DATACMNS-142 - Polished API of UserCredentials.

Added constant to represent no credentials. Removed empty constructor. Added methods to ask whether username or password is configured.
This commit is contained in:
Oliver Gierke
2012-04-02 15:24:09 +02:00
parent b4d21008e3
commit cb375b250f
2 changed files with 60 additions and 4 deletions

View File

@@ -32,6 +32,46 @@ public class UserCredentialsUnitTests {
UserCredentials credentials = new UserCredentials("", "");
assertThat(credentials.getUsername(), is(nullValue()));
assertThat(credentials.hasUsername(), is(false));
assertThat(credentials.getPassword(), is(nullValue()));
assertThat(credentials.hasPassword(), is(false));
}
/**
* @see DATACMNS-142
*/
@Test
public void noCredentialsNullsUsernameAndPassword() {
assertThat(UserCredentials.NO_CREDENTIALS.getUsername(), is(nullValue()));
assertThat(UserCredentials.NO_CREDENTIALS.getPassword(), is(nullValue()));
}
/**
* @see DATACMNS-142
*/
@Test
public void configuresUsernameCorrectly() {
UserCredentials credentials = new UserCredentials("username", null);
assertThat(credentials.hasUsername(), is(true));
assertThat(credentials.getUsername(), is("username"));
assertThat(credentials.hasPassword(), is(false));
assertThat(credentials.getPassword(), is(nullValue()));
}
/**
* @see DATACMNS-142
*/
@Test
public void configuresPasswordCorrectly() {
UserCredentials credentials = new UserCredentials(null, "password");
assertThat(credentials.hasUsername(), is(false));
assertThat(credentials.getUsername(), is(nullValue()));
assertThat(credentials.hasPassword(), is(true));
assertThat(credentials.getPassword(), is("password"));
}
}