DS-3406: Resolve review feedback

This commit is contained in:
Tom Desair
2017-05-02 17:59:25 +02:00
parent 3540fe5ec6
commit e358cb84d1
3 changed files with 22 additions and 4 deletions

View File

@@ -226,7 +226,7 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport
}
/**
* Get the collections this item is in. The order is indeterminate.
* Get the collections this item is in. The order is sorted ascending by collection name.
*
* @return the collections this item is in, if any.
*/

View File

@@ -7,7 +7,7 @@
*/
package org.dspace.content.comparator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.dspace.content.DSpaceObject;
import java.util.Comparator;
@@ -23,7 +23,9 @@ public class NameAscendingComparator implements Comparator<DSpaceObject>{
}else if (dso2 == null){
return 1;
}else {
return ObjectUtils.compare(dso1.getName(),dso2.getName());
String name1 = StringUtils.trimToEmpty(dso1.getName());
String name2 = StringUtils.trimToEmpty(dso2.getName());
return name1.compareToIgnoreCase(name2);
}
}
}

View File

@@ -61,7 +61,7 @@ public class NameAscendingComparatorTest {
@Test
public void testCompareSecondNull() throws Exception {
when(dso2.getName()).thenReturn("b");
when(dso1.getName()).thenReturn("a");
assertTrue(comparator.compare(dso1, null) > 0);
}
@@ -78,4 +78,20 @@ public class NameAscendingComparatorTest {
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);
}
}