NameAscendingComparator implements Comparator<DSpaceObject> { @Override public int compare(DSpaceObject dso1, DSpaceObject dso2) { if (dso1 == dso2){ return 0; }else if (dso1 == null){ return -1; }else if (dso2 == null){ return 1; }else { String name1 = StringUtils.trimToEmpty(dso1.getName()); String name2 = StringUtils.trimToEmpty(dso2.getName()); if(name1.equals(name2)) { return ObjectUtils.compare(dso1.getID(), dso2.getID()); } else { return name1.compareToIgnoreCase(name2); } } }  @Override int compare(DSpaceObject dso1, DSpaceObject dso2);  }
@Test public void testCompareLessThan() throws Exception { when(dso1.getName()).thenReturn("a"); when(dso2.getName()).thenReturn("b"); assertTrue(comparator.compare(dso1, dso2) < 0); }
@Test public void testCompareGreaterThan() throws Exception { when(dso1.getName()).thenReturn("b"); when(dso2.getName()).thenReturn("a"); assertTrue(comparator.compare(dso1, dso2) > 0); }
@Test public void testCompareEqual() throws Exception { when(dso1.getName()).thenReturn("b"); when(dso2.getName()).thenReturn("b"); assertTrue(comparator.compare(dso1, dso2) == 0); }
@Test public void testCompareFirstNull() throws Exception { when(dso2.getName()).thenReturn("b"); assertTrue(comparator.compare(null, dso2) < 0); }
@Test public void testCompareSecondNull() throws Exception { when(dso1.getName()).thenReturn("a"); assertTrue(comparator.compare(dso1, null) > 0); }
@Test public void testCompareBothNull() throws Exception { assertTrue(comparator.compare(null, null) == 0); }
@Test public void testCompareNameNull() throws Exception { when(dso1.getName()).thenReturn(null); when(dso2.getName()).thenReturn("b"); assertTrue(comparator.compare(dso1, dso2) < 0); }
@Test public void testCompareCaseInsensitive() throws Exception { when(dso1.getName()).thenReturn("a"); when(dso2.getName()).thenReturn("B"); assertTrue(comparator.compare(dso1, dso2) < 0); }
@Test public void testCompareCaseTrimmed() throws Exception { when(dso1.getName()).thenReturn("a"); when(dso2.getName()).thenReturn(" b "); assertTrue(comparator.compare(dso1, dso2) < 0); }