ObjectUtils { public static boolean equals(Object object1, Object object2) { if (object1 == object2) { return true; } else if (object1 == null || object2 == null) { return false; } else if (object1 instanceof Enum && object2 instanceof String) { return ((Enum<?>) object1).name().equals(object2); } else if (object1 instanceof String && object2 instanceof Enum) { return object1.equals(((Enum<?>) object2).name()); } else { return object1.equals(object2); } }  static boolean equals(Object object1, Object object2); static int hashCode(Object... objects); static T firstNonNull(T... values); static T firstNonBlank(T... values); @Deprecated static T coalesce(T... values); static ClassLoader getCurrentClassLoader(); static Class<?> getClassFromLoader(ClassLoader loader, String name); static Class<?> getClassByName(String name); static int compare(Object object1, Object object2, boolean isNullGreatest); static void sort(List<?> list, boolean isNullGreatest); static boolean isBlank(Object object); @Deprecated static Set<Class<? extends T>> findClassesFromLoader(ClassLoader loader, Class<T> baseClass); @Deprecated static Set<Class<? extends T>> findClasses(Class<T> baseClass); static Object to(Type returnType, Object object); static T to(Class<T> returnClass, Object object); static T to(TypeReference<T> returnTypeReference, Object object); static Object toOrError(Type returnType, Object object); static T toOrError(Class<T> returnClass, Object object); static T toOrError(TypeReference<T> returnTypeReference, Object object); static Object fromJson(String string); static Object fromJson(byte[] bytes); static String toJson(Object object); static String toJson(Object object, boolean isIndentOutput); @Deprecated static String toJson(Object object, boolean isIndentOutput, Transformer transformer); static String getContentType(String path); static double jitterAbsolutely(double number, double amount); static long jitterAbsolutely(long number, long amount); static double jitter(double number, double scale); static long jitter(long number, double scale); @Deprecated static int compareTo(Object object1, Object object2); @Deprecated static T newInstance(Class<T> objectClass); @Deprecated static Object getValue(Object object, String name); @Deprecated @SuppressWarnings("all") static Set<Class<?>> findClasses(ClassLoader loader, Class<?> baseClass); @Deprecated static Byte asByte(Object byteLike); @Deprecated static Date asDate(Object dateLike); @Deprecated static T asEnum(Class<T> type, Object enumLike); @Deprecated static Double asDouble(Object doubleLike); @Deprecated static Float asFloat(Object floatLike); @Deprecated static Integer asInteger(Object integerLike); @Deprecated static Long asLong(Object longLike); @Deprecated static Short asShort(Object shortLike); @Deprecated static UUID asUuid(Object uuidLike); @Deprecated static void errorIf(boolean condition, String parameterName, String message); @Deprecated static void errorIfNull(Object object, String parameterName); @Deprecated static void errorIfBlank(Object object, String parameterName); @Deprecated static Object getByPath(Object object, String path); static final String DEFAULT_CONTENT_TYPE; }
@Test public void equals_null() { assertEquals(false, ObjectUtils.equals(null, new Object())); assertEquals(false, ObjectUtils.equals(new Object(), null)); }
@Test public void equals_null_both() { assertEquals(true, ObjectUtils.equals(null, null)); }
@Test public void equals_null_generic_true() { assertEquals(true, ObjectUtils.equals("hello", "hello")); }
@Test public void equals_null_generic_false() { assertEquals(false, ObjectUtils.equals("hello", "goodbye")); }
@Test public void equals_null_enum_true() { assertEquals(true, ObjectUtils.equals(TestEnum.value1, "value1")); assertEquals(true, ObjectUtils.equals("value2", TestEnum.value2)); }
@Test public void equals_null_enum_case_sensitive() { assertEquals(false, ObjectUtils.equals(TestEnum.value1, "VALUE1")); }