@Test public void compareTo_currentContactGivenNameNull() { Contact contact1 = new Contact("id"); contact1.givenName = null; Contact contact2 = new Contact("id2"); contact2.givenName = "b"; assertThat(contact1.compareTo(contact2)) .isLessThan(0); }
@Override public int compareTo(Contact contact) { String givenName1 = this.givenName == null ? "" : this.givenName.toLowerCase(); String givenName2 = contact == null ? "" : (contact.givenName == null ? "" : contact.givenName.toLowerCase()); return givenName1.compareTo(givenName2); }
Contact implements Comparable<Contact> { @Override public int compareTo(Contact contact) { String givenName1 = this.givenName == null ? "" : this.givenName.toLowerCase(); String givenName2 = contact == null ? "" : (contact.givenName == null ? "" : contact.givenName.toLowerCase()); return givenName1.compareTo(givenName2); } }
Contact implements Comparable<Contact> { @Override public int compareTo(Contact contact) { String givenName1 = this.givenName == null ? "" : this.givenName.toLowerCase(); String givenName2 = contact == null ? "" : (contact.givenName == null ? "" : contact.givenName.toLowerCase()); return givenName1.compareTo(givenName2); } Contact(String id); private  Contact(); }
Contact implements Comparable<Contact> { @Override public int compareTo(Contact contact) { String givenName1 = this.givenName == null ? "" : this.givenName.toLowerCase(); String givenName2 = contact == null ? "" : (contact.givenName == null ? "" : contact.givenName.toLowerCase()); return givenName1.compareTo(givenName2); } Contact(String id); private  Contact(); @Override int compareTo(Contact contact); }
Contact implements Comparable<Contact> { @Override public int compareTo(Contact contact) { String givenName1 = this.givenName == null ? "" : this.givenName.toLowerCase(); String givenName2 = contact == null ? "" : (contact.givenName == null ? "" : contact.givenName.toLowerCase()); return givenName1.compareTo(givenName2); } Contact(String id); private  Contact(); @Override int compareTo(Contact contact);  }