### Question:
TreatmentDefinition extends AbstractEntity implements Comparable<TreatmentDefinition> { @Override public int compareTo(TreatmentDefinition o) { Iterator<Category> i1 = getContents().iterator(); Iterator<Category> i2 = o.getContents().iterator(); while (i1.hasNext() && i2.hasNext()) { int compVal = i1.next().compareTo(i2.next()); if (compVal != 0) { return compVal; } } if (i1.hasNext()) { return 1; } if (i2.hasNext()) { return -1; } return 0; } TreatmentDefinition(Category category);  TreatmentDefinition(Collection<Category> contents);  TreatmentDefinition(); static TreatmentDefinition createTrivial(Collection<Drug> drugs); static TreatmentDefinition createTrivial(Drug drug); @Override Set<? extends Entity> getDependencies(); SortedSet<Category> getContents(); String getLabel(); @Override boolean equals(Object o); @Override boolean deepEquals(Entity o); @Override int hashCode(); @Override int compareTo(TreatmentDefinition o); @Override String toString(); boolean match(TreatmentActivity act); boolean match(Study study, Arm arm);  }### Answer:
@Test public void testCompareTo() { assertEquals(0, d_empty.compareTo(d_empty)); assertEquals(0, d_empty.compareTo(new TreatmentDefinition())); assertEquals(0, d_single.compareTo(new TreatmentDefinition(d_singleCategory))); assertEquals(0, d_multi.compareTo(new TreatmentDefinition(d_multiCategory))); assertTrue(d_empty.compareTo(d_single) < 0); assertTrue(d_single.compareTo(TreatmentDefinition.createTrivial(ExampleData.buildDrugCitalopram())) > 0); assertEquals(d_empty.compareTo(d_single), -d_single.compareTo(d_empty)); TreatmentDefinition two1 = new TreatmentDefinition(Arrays.asList(new Category[] { d_singleCategory, Category.createTrivial(ExampleData.buildDrugCitalopram()) })); assertTrue(d_single.compareTo(two1) > 0); TreatmentDefinition two2 = new TreatmentDefinition(Arrays.asList(new Category[] { d_singleCategory, Category.createTrivial(ExampleData.buildDrugFluoxetine()) })); assertTrue(d_single.compareTo(two2) < 0); }