### Question:
EntitySelection implements Comparable<EntitySelection> { @Override public int compareTo(EntitySelection entitySelection) { if (entitySelection == null) { throw new NullPointerException("Provided entitySelection should not be null."); } if (entitySelection == this) { return 0; } if (entityReference == null) { return -1; } if (entitySelection.entityReference == null) { return 1; } int result = entityReference.compareTo(entitySelection.entityReference); if (result == 0) { return isSelected.compareTo(entitySelection.isSelected); } else { return result; } } EntitySelection(EntityReference entityReference); EntityReference getEntityReference(); boolean isSelected(); State getState(); void setSelected(boolean selected); @Override int hashCode(); @Override boolean equals(Object object); @Override int compareTo(EntitySelection entitySelection);  }### Answer:
@Test void compareTo() { EntityReference aEntityReference = new EntityReference("A", EntityType.PAGE); EntitySelection aEntitySelection = new EntitySelection(aEntityReference); assertThrows(NullPointerException.class, () -> { aEntitySelection.compareTo(null); }); assertEquals(0, aEntitySelection.compareTo(aEntitySelection)); EntitySelection aPrimeEntitySelection = new EntitySelection(aEntityReference); assertEquals(0, aEntitySelection.compareTo(aPrimeEntitySelection)); aEntitySelection.setSelected(true); assertEquals(-2, aEntitySelection.compareTo(aPrimeEntitySelection)); aEntitySelection.setSelected(false); assertEquals(-1, aEntitySelection.compareTo(aPrimeEntitySelection)); EntityReference bEntityReference = new EntityReference("B", EntityType.PAGE); EntitySelection bEntitySelection = new EntitySelection(bEntityReference); assertEquals(-1, aEntitySelection.compareTo(bEntitySelection)); }
@Test void compareToEntityReferenceNull() { EntitySelection o = new EntitySelection(null); assertEquals(-1, o.compareTo(new EntitySelection(null))); }
@Test void compareToEntitySelectionReferenceNull() { EntitySelection o = new EntitySelection(new EntityReference("A", EntityType.PAGE)); assertEquals(1, o.compareTo(new EntitySelection(null))); }