Utils { public static int compareStrings(final String s, final String p) { if (isNullOrEmpty(s)) { if (!isNullOrEmpty(p)) { return 2; } else { return -1; } } else if (!isNullOrEmpty(p)) { if (s.equals(p)) { return 0; } else { return -2; } } else { return 1; } }  static String toXMLDateTime(final Date date); static Date fromXMLDateTime(final String xmlDateTimeString); static String detectMimeType(final File f); static String getExtension(final String mimeType); static Path createFileWithUniqueName(final String baseName); static void sortFiles(final File array[]); static String getKeyByValue(final Map<String, String> map, final String value); static int compareStrings(final String s, final String p); static String getValue(final String value, final String defaultValue); static boolean isNullOrEmpty(final String s); static boolean isNullOrEmpty(final Collection<?> c); static boolean isNullOrEmpty(final Map<?,?> m); static boolean isNullOrEmpty(final Iterator<?> i); static Throwable getRootCause(final Throwable t); static List<Throwable> getCauses(final Throwable t); static String getExceptionTrace(final Throwable t); static boolean nullSafeEqual(final T o1, final T o2); static boolean nullSafeEqualIgnoreCase(final String s1, final String s2); static boolean isValidURI(final String uri); static boolean isTrue(String value);  }
@Test public void testCompareStrings() { assertTrue(Utils.compareStrings("a", "b") == -2); assertTrue(Utils.compareStrings(null, null) == -1); assertTrue(Utils.compareStrings(null, "") == -1); assertTrue(Utils.compareStrings("", null) == -1); assertTrue(Utils.compareStrings("", "") == -1); assertTrue(Utils.compareStrings("a", "a") == 0); assertTrue(Utils.compareStrings("a", "") == 1); assertTrue(Utils.compareStrings("a", null) == 1); assertTrue(Utils.compareStrings(null, "b") == 2); assertTrue(Utils.compareStrings("", "b") == 2); }