parent
b2ed230b32
commit
40e5f03804
2 changed files with 21 additions and 1 deletions
|
@ -173,7 +173,10 @@ public class Address implements Serializable {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = mAddress.hashCode();
|
||||
int hash = 0;
|
||||
if (mAddress != null) {
|
||||
hash += mAddress.hashCode();
|
||||
}
|
||||
if (mPersonal != null) {
|
||||
hash += 3 * mPersonal.hashCode();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
|
@ -89,4 +90,20 @@ public class AddressTest {
|
|||
assertEquals("\"sa\"mp\"le\"", Address.quoteString("\"sa\"mp\"le\""));
|
||||
assertEquals("\"\"\"", Address.quoteString("\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withoutAddress() throws Exception {
|
||||
Address address = Address.parse("name only")[0];
|
||||
assertNull(address.getAddress());
|
||||
|
||||
address.hashCode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_withoutPersonal() throws Exception {
|
||||
Address address = Address.parse("alice@example.org")[0];
|
||||
assertNull(address.getPersonal());
|
||||
|
||||
address.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue