mirror of https://github.com/apache/jclouds.git
JCLOUDS-549: Fix NPE in LoginCredentials.toString
This commit is contained in:
parent
4a729562dd
commit
25c37fc8ca
|
@ -207,7 +207,8 @@ public class LoginCredentials extends Credentials {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[user=" + getUser() + ", passwordPresent=" + password.isPresent() + ", privateKeyPresent="
|
||||
+ privateKey.isPresent() + ", shouldAuthenticateSudo=" + authenticateSudo + "]";
|
||||
return "[user=" + getUser() + ", passwordPresent=" + (password != null ? password.isPresent() : false)
|
||||
+ ", privateKeyPresent=" + (privateKey != null ? privateKey.isPresent() : false)
|
||||
+ ", shouldAuthenticateSudo=" + authenticateSudo + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.jclouds.domain;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -51,4 +52,15 @@ public class LoginCredentialsTest {
|
|||
assertEquals(toTest.getOptionalPassword(), Optional.of("password"));
|
||||
assertEquals(toTest.getOptionalPrivateKey(), Optional.of("key"));
|
||||
}
|
||||
|
||||
public void testToStringWhenNullPasswordAndKey() {
|
||||
LoginCredentials toTest = LoginCredentials.builder().user("myuser").build();
|
||||
// also verifies that toString() does not blow up with an NPE
|
||||
assertNotNull(toTest.toString());
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
LoginCredentials toTest = LoginCredentials.builder().user("myuser").password("password").privateKey("key").build();
|
||||
assertNotNull(toTest.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue