CompareUtil { public static boolean nullSafeEquals(Object obj1, Object obj2) { if (obj1 != null) { return obj1.equals(obj2); } return obj2 == null; } private  CompareUtil(); static boolean nullSafeEquals(Object obj1, Object obj2); static int nullSafeHashCode(Object obj);  }
@Test public void testNullSafeEquals() { assertTrue(CompareUtil.nullSafeEquals(1, 1)); assertFalse(CompareUtil.nullSafeEquals(1, 2)); assertFalse(CompareUtil.nullSafeEquals(1, null)); assertFalse(CompareUtil.nullSafeEquals(null, 1)); assertTrue(CompareUtil.nullSafeEquals(null, null)); }