ObjectUtils { @Deprecated public static int compareTo(Object object1, Object object2) { if (object1 == null || object2 == null) { throw new NullPointerException( "The [object1] and [object2] parameters cannot be null!"); } else { Class<?> o1c = object1.getClass(); Class<?> o2c = object2.getClass(); if (Comparable.class.isAssignableFrom(o1c) && o1c.isAssignableFrom(o2c)) { @SuppressWarnings("unchecked") Comparable<Object> object1Comparable = (Comparable<Object>) object1; return object1Comparable.compareTo(object2); } else if (Comparable.class.isAssignableFrom(o2c) && o2c.isAssignableFrom(o1c)) { @SuppressWarnings("unchecked") Comparable<Object> object2Comparable = (Comparable<Object>) object2; return 0 - object2Comparable.compareTo(object1); } else { throw new IllegalArgumentException( "The [object1] and [object2] parameters must be" + " compatible and comparable!"); } } }  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 (expected=NullPointerException.class) public void compareTo_null_1() { assertEquals(false, ObjectUtils.compareTo(null, new Object())); }
@Test (expected=NullPointerException.class) public void compareTo_null_2() { assertEquals(false, ObjectUtils.compareTo(new Object(), null)); }
@Test public void compareTo_same_class_less() { assertEquals(-1, ObjectUtils.compareTo("hello1", "hello2")); }
@Test public void compareTo_same_class_equal() { assertEquals(0, ObjectUtils.compareTo("hello", "hello")); }
@Test public void compareTo_same_class_greater() { assertEquals(1, ObjectUtils.compareTo("hello2", "hello1")); }
@Test public void compareTo_assignable_assignable_second() { assertEquals(0, ObjectUtils.compareTo(new CompareParent("hello"), new CompareChild("hello"))); }
@Test public void compareTo_assignable_less() { assertEquals(-1, ObjectUtils.compareTo(new CompareParent("hello1"), new CompareChild("hello2"))); }
@Test (expected=IllegalArgumentException.class) public void compareTo_not_assignable() { assertEquals(0, ObjectUtils.compareTo(new CompareOne(), new CompareTwo())); }
@Test (expected=IllegalArgumentException.class) public void compareTo_not_comparable() { assertEquals(0, ObjectUtils.compareTo(new NotComparableParent(), new NotComparableChild())); }