### Question:
ServiceDefinitionComparator implements Comparator<ServiceDefinition> { @Override public int compare(ServiceDefinition serviceDefinition, ServiceDefinition otherServiceDefinition) { if (serviceDefinition == null || otherServiceDefinition == null) { throw new IllegalArgumentException("One (or both) of the supplied service definitions is null"); } final int byName = serviceDefinition.getName().compareTo(otherServiceDefinition.getName()); if(byName != 0) { return byName; } final int byRole = serviceDefinition.getRole().compareTo(otherServiceDefinition.getRole()); if(byRole != 0) { return byRole; } return serviceDefinition.getVersion().compareTo(otherServiceDefinition.getVersion()); }  @Override int compare(ServiceDefinition serviceDefinition, ServiceDefinition otherServiceDefinition);  }### Answer:
@Test public void shouldCompareByName() throws Exception { assertEquals(-1, serviceDefinitionComparator.compare(buildServiceDefinition("service1", "role1", "1.0"), buildServiceDefinition("service2", "role1", "1.0"))); }
@Test public void shouldCompareByRole() throws Exception { assertEquals(-1, serviceDefinitionComparator.compare(buildServiceDefinition("service1", "role1", "1.0"), buildServiceDefinition("service1", "role2", "1.0"))); }
@Test public void shouldCompareByVersion() throws Exception { assertEquals(-1, serviceDefinitionComparator.compare(buildServiceDefinition("service1", "role1", "1.0"), buildServiceDefinition("service1", "role1", "2.0"))); }
@Test public void shouldReturnZeroIfAllEquals() throws Exception { assertEquals(0, serviceDefinitionComparator.compare(buildServiceDefinition("service1", "role1", "1.0"), buildServiceDefinition("service1", "role1", "1.0"))); }