Address: Handle getHostname when mAddress is null

This commit is contained in:
Philip Whitehouse 2017-02-08 22:53:08 +00:00
parent 19b7d4491d
commit 9207afdc69
2 changed files with 13 additions and 0 deletions

View file

@ -78,6 +78,10 @@ public class Address implements Serializable {
} }
public String getHostname() { public String getHostname() {
if (mAddress == null) {
return null;
}
int hostIdx = mAddress.lastIndexOf("@"); int hostIdx = mAddress.lastIndexOf("@");
if (hostIdx == -1) { if (hostIdx == -1) {

View file

@ -148,4 +148,13 @@ public class AddressTest {
assertFalse(result); assertFalse(result);
} }
@Test
public void getHostname_withoutAddress_isNull() throws Exception {
Address address = Address.parse("Alice")[0];
String result = address.getHostname();
assertNull(result);
}
} }