### Question:
CohortMembership extends BaseChangeableOpenmrsData implements Comparable<CohortMembership> { @Override public int compareTo(CohortMembership o) { int ret = this.getVoided().compareTo(o.getVoided()); if (ret == 0) { ret = -OpenmrsUtil.compareWithNullAsLatest(this.getEndDate(), o.getEndDate()); } if (ret == 0) { ret = -OpenmrsUtil.compareWithNullAsEarliest(this.getStartDate(), o.getStartDate()); } if (ret == 0) { ret = this.getPatientId().compareTo(o.getPatientId()); } if (ret == 0) { ret = this.getUuid().compareTo(o.getUuid()); } return ret; } CohortMembership();  CohortMembership(Integer patientId, Date startDate);  CohortMembership(Integer patientId); boolean isActive(Date asOfDate); boolean isActive(); @Override Integer getId(); @Override void setId(Integer id); Integer getCohortMemberId(); void setCohortMemberId(Integer cohortMemberId); Cohort getCohort(); void setCohort(Cohort cohort); Integer getPatientId(); void setPatientId(Integer patientId); Date getStartDate(); void setStartDate(Date startDate); Date getEndDate(); void setEndDate(Date endDate); @Override int compareTo(CohortMembership o); static final long serialVersionUID; }### Answer:
@Test public void compareTo_shouldCompareBasedOnPatientId() { Date date = new Date(); CohortMembership firstMembership = new CohortMembership(4, date); CohortMembership secondMembership = new CohortMembership(7, date); assertThat(firstMembership.compareTo(secondMembership), lessThan(0)); assertThat(secondMembership.compareTo(firstMembership), greaterThan(0)); }