Skip to content
Snippets Groups Projects
Commit 8e2515d9 authored by buczekp's avatar buczekp
Browse files

[LMS-1412] primitive value comparator test

SVN: 15047
parent 7f47248b
No related branches found
No related tags found
No related merge requests found
...@@ -26,8 +26,7 @@ import java.util.List; ...@@ -26,8 +26,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.comparators.NullComparator; import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections.comparators.ReverseComparator;
import org.apache.commons.lang.text.StrMatcher; import org.apache.commons.lang.text.StrMatcher;
import org.apache.commons.lang.text.StrTokenizer; import org.apache.commons.lang.text.StrTokenizer;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -266,8 +265,8 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se ...@@ -266,8 +265,8 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se
}; };
// null values will be treated as smallestte // null values will be treated as smallest
return applySortDir(sortDir, new NullComparator(comparator, false)); return applySortDir(sortDir, ComparatorUtils.nullLowComparator(comparator));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -275,7 +274,7 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se ...@@ -275,7 +274,7 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se
{ {
if (sortDir == SortDir.DESC) if (sortDir == SortDir.DESC)
{ {
return new ReverseComparator(comparator); return ComparatorUtils.reversedComparator(comparator);
} else } else
{ {
return comparator; return comparator;
......
package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import org.testng.AssertJUnit;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.shared.basic.PrimitiveValue;
/**
* @author Piotr Buczek
*/
public class PrimitiveValueTest extends AssertJUnit
{
private enum ExpectedResult
{
LOWER, EQUAL, HIGHER;
}
@DataProvider(name = "values")
protected Object[][] getValues()
{
return new Object[][]
{
/* NULL == NULL == "" */
{ PrimitiveValue.NULL, PrimitiveValue.NULL, ExpectedResult.EQUAL },
{ PrimitiveValue.NULL, new PrimitiveValue(""), ExpectedResult.EQUAL },
/* NULL < anything else */
{ PrimitiveValue.NULL, new PrimitiveValue("text"), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue("5"), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(-10L), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(0L), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(10L), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(-10.0), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(0.0), ExpectedResult.LOWER },
{ PrimitiveValue.NULL, new PrimitiveValue(10.0), ExpectedResult.LOWER },
/* String < Number */
{ new PrimitiveValue("text"), new PrimitiveValue(-10L), ExpectedResult.LOWER },
{ new PrimitiveValue("text"), new PrimitiveValue(0L), ExpectedResult.LOWER },
{ new PrimitiveValue("text"), new PrimitiveValue(10L), ExpectedResult.LOWER },
{ new PrimitiveValue("text"), new PrimitiveValue(-10.0), ExpectedResult.LOWER },
{ new PrimitiveValue("text"), new PrimitiveValue(0.0), ExpectedResult.LOWER },
{ new PrimitiveValue("text"), new PrimitiveValue(10.0), ExpectedResult.LOWER },
/* String number < Number */
{ new PrimitiveValue("5"), new PrimitiveValue(5L), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(-10L), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(0L), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(10L), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(-10.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(0.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5"), new PrimitiveValue(10.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(5.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(-10L), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(0L), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(10L), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(-10.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(0.0), ExpectedResult.LOWER },
{ new PrimitiveValue("5.0"), new PrimitiveValue(10.0), ExpectedResult.LOWER },
/* String vs String */
{ new PrimitiveValue("aba"), new PrimitiveValue("aba"), ExpectedResult.EQUAL },
{ new PrimitiveValue("aba"), new PrimitiveValue("abc"), ExpectedResult.LOWER },
{ new PrimitiveValue("abc"), new PrimitiveValue("abca"), ExpectedResult.LOWER },
{ new PrimitiveValue("aba"), new PrimitiveValue("abca"), ExpectedResult.LOWER },
/* Long vs Long */
{ new PrimitiveValue(10L), new PrimitiveValue(10L), ExpectedResult.EQUAL },
{ new PrimitiveValue(-10L), new PrimitiveValue(0L), ExpectedResult.LOWER },
{ new PrimitiveValue(-10L), new PrimitiveValue(10L), ExpectedResult.LOWER },
{ new PrimitiveValue(5L), new PrimitiveValue(10L), ExpectedResult.LOWER },
/* Double vs Double */
{ new PrimitiveValue(9.9), new PrimitiveValue(9.9), ExpectedResult.EQUAL },
{ new PrimitiveValue(9.9), new PrimitiveValue(10.0), ExpectedResult.LOWER },
/* Long vs Double */
{ new PrimitiveValue(0L), new PrimitiveValue(0.0), ExpectedResult.EQUAL },
{ new PrimitiveValue(10L), new PrimitiveValue(10.0), ExpectedResult.EQUAL },
{ new PrimitiveValue(-10L), new PrimitiveValue(-5.0), ExpectedResult.LOWER },
{ new PrimitiveValue(9.9), new PrimitiveValue(10L), ExpectedResult.LOWER },
};
}
@Test(dataProvider = "values")
public void testComparison(PrimitiveValue v1, PrimitiveValue v2, ExpectedResult expectedResult)
{
switch (expectedResult)
{
case EQUAL:
assertTrue(v1.compareTo(v2) == 0);
assertTrue(v2.compareTo(v1) == 0);
break;
case LOWER:
assertTrue(v1.compareTo(v2) < 0);
assertTrue(v2.compareTo(v1) > 0);
break;
case HIGHER:
assertTrue(v1.compareTo(v2) > 0);
assertTrue(v2.compareTo(v1) < 0);
break;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment