CompareUtil { @SuppressWarnings({"unchecked", "rawtypes"}) public static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final OrderDirection nullOrderDirection, final boolean caseSensitive) { if (null == thisValue && null == otherValue) { return 0; } if (null == thisValue) { return orderDirection == nullOrderDirection ? -1 : 1; } if (null == otherValue) { return orderDirection == nullOrderDirection ? 1 : -1; } if (!caseSensitive && thisValue instanceof String && otherValue instanceof String) { return compareToCaseInsensitiveString((String) thisValue, (String) otherValue, orderDirection); } return OrderDirection.ASC == orderDirection ? thisValue.compareTo(otherValue) : -thisValue.compareTo(otherValue); }  @SuppressWarnings({"unchecked", "rawtypes"}) static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final OrderDirection nullOrderDirection, final boolean caseSensitive);  }
@Test public void assertCompareToWhenBothNull() { assertThat(CompareUtil.compareTo(null, null, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(0)); }
@Test public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullOrderByAsc() { assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(-1)); }
@Test public void assertCompareToWhenFirstValueIsNullForOrderByAscAndNullOrderByDesc() { assertThat(CompareUtil.compareTo(null, 1, OrderDirection.ASC, OrderDirection.DESC, caseSensitive), is(1)); }
@Test public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullOrderByAsc() { assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(1)); }
@Test public void assertCompareToWhenFirstValueIsNullForOrderByDescAndNullOrderByDesc() { assertThat(CompareUtil.compareTo(null, 1, OrderDirection.DESC, OrderDirection.DESC, caseSensitive), is(-1)); }
@Test public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullOrderByAsc() { assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(1)); }
@Test public void assertCompareToWhenSecondValueIsNullForOrderByAscAndNullOrderByDesc() { assertThat(CompareUtil.compareTo(1, null, OrderDirection.ASC, OrderDirection.DESC, caseSensitive), is(-1)); }
@Test public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullOrderByAsc() { assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(-1)); }
@Test public void assertCompareToWhenSecondValueIsNullForOrderByDescAndNullOrderByDesc() { assertThat(CompareUtil.compareTo(1, null, OrderDirection.DESC, OrderDirection.DESC, caseSensitive), is(1)); }
@Test public void assertCompareToWhenAsc() { assertThat(CompareUtil.compareTo(1, 2, OrderDirection.ASC, OrderDirection.ASC, caseSensitive), is(-1)); }
@Test public void assertCompareToWhenDesc() { assertThat(CompareUtil.compareTo(1, 2, OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(1)); }
@Test public void assetCompareToStringWithCaseSensitive() { assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, OrderDirection.ASC, caseSensitive), is(32)); }
@Test public void assetCompareToStringWithCaseInsensitive() { assertThat(CompareUtil.compareTo("A", "a", OrderDirection.DESC, OrderDirection.ASC, !caseSensitive), is(0)); }