### Question:
PatientComparator implements Comparator<Patient> { @Override public int compare(Patient patient1, Patient patient2) { if (patient1 == null) { patient1 = new Patient(); } if (patient2 == null) { patient2 = new Patient(); } int familyNameCompareResult = StringUtils.nullSafeCompare(patient1.getFamilyName(), patient2.getFamilyName()); if (familyNameCompareResult != 0) { return familyNameCompareResult; } int givenNameCompareResult = StringUtils.nullSafeCompare(patient1.getGivenName(), patient2.getGivenName()); if (givenNameCompareResult != 0) { return givenNameCompareResult; } return StringUtils.nullSafeCompare(patient1.getMiddleName(), patient2.getMiddleName()); }  @Override int compare(Patient patient1, Patient patient2);  }### Answer:
@Test public void shouldSortByFamilyName() { Patient obama = patient("Obama", "Barack", "Hussein", "id1"); Patient bush = patient("Bush", "George", "W", "id2"); assertTrue(patientComparator.compare(obama, bush) > 0); }
@Test public void shouldSortByGivenNameIfFamilyNameIsSame() { Patient barack = patient("Obama", "Barack", "Hussein", "id1"); Patient george = patient("Obama", "George", "W", "id2"); assertTrue(patientComparator.compare(barack, george) < 0); }
@Test public void shouldSortByMiddleNameIfGivenNameAndFamilyNameAreSame() { Patient hussein = patient("Obama", "Barack", "Hussein", "id1"); Patient william = patient("Obama", "Barack", "William", "id2"); assertTrue(patientComparator.compare(hussein, william) < 0); }