StringUtils { public static int compare(String str1, String str2) { if( str1 == null || str2 == null) { throw new IllegalArgumentException("Arguments cannot be null"); } Collator collator = Collator.getInstance(LOCALE_ENGLISH); return collator.compare(str1, str2); }  static Integer toInteger(StringBuilder value); static String toString(StringBuilder value); static Boolean toBoolean(StringBuilder value); static String fromInteger(Integer value); static String fromLong(Long value); static String fromShort(Short value); static String fromString(String value); static String fromBoolean(Boolean value); static String fromBigInteger(BigInteger value); static String fromBigDecimal(BigDecimal value); static BigInteger toBigInteger(String s); static BigDecimal toBigDecimal(String s); static String fromFloat(Float value); static String fromDate(Date value); static String fromDate(Date date, String timestampFormat); static String fromDouble(Double d); static String fromByte(Byte b); static String fromByteBuffer(ByteBuffer byteBuffer); static String replace( String originalString, String partToMatch, String replacement ); static String join(String joiner, String... parts); static String trim(String value); static boolean isNullOrEmpty(String value); static boolean hasValue(String str); static String lowerCase(String str); static String upperCase(String str); static int compare(String str1, String str2); static void appendCompactedString(final StringBuilder destination, final String source); static boolean beginsWithIgnoreCase(final String data, final String seq); static Character findFirstOccurrence(String s, char ...charsToMatch); static final String COMMA_SEPARATOR; static final Charset UTF8; }
@Test public void testCompare() { assertTrue(StringUtils.compare("truck", "Car") > 0); assertTrue(StringUtils.compare("", "dd") < 0); assertTrue(StringUtils.compare("dd", "") > 0); assertEquals(0, StringUtils.compare("", "")); assertTrue(StringUtils.compare(" ", "") > 0); }
@Test (expected = IllegalArgumentException.class) public void testCompare_String1Null() { String str1 = null; String str2 = "test"; int result = StringUtils.compare(str1, str2); }
@Test (expected = IllegalArgumentException.class) public void testCompare_String2Null() { String str1 = "test"; String str2 = null; int result = StringUtils.compare(str1, str2); }