ComparableUtils { public static <T> int safeCompare(Comparable<T> d1, T d2) { if (d1 != null && d2 != null) { return d1.compareTo(d2); } else if (d1 == null && d2 != null) { return -1; } else if (d1 != null && d2 == null) { return 1; } else { return 0; } }  static int safeCompare(Comparable<T> d1, T d2);  }
@Test public void safeCompare_SecondNull_ReturnsPositive() { assertThat(ComparableUtils.safeCompare(1.0, null), greaterThan(0)); }
@Test public void safeCompare_FirstNull_ReturnsNegative() { assertThat(ComparableUtils.safeCompare(null, 7.0), lessThan(0)); }
@Test public void safeCompare_BothNull_ReturnsZero() { assertThat(ComparableUtils.safeCompare(null, null), equalTo(0)); }
@Test public void safeCompare_FirstLarger_ReturnsPositive() { assertThat(ComparableUtils.safeCompare(7.0, 6.0), greaterThan(0)); }
@Test public void safeCompare_SecondLarger_ReturnsNegative() { assertThat(ComparableUtils.safeCompare(6.0, 7.0), lessThan(0)); }