Address: Handle getHostname when mAddress is null
This commit is contained in:
parent
19b7d4491d
commit
9207afdc69
2 changed files with 13 additions and 0 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue