< prev index next >

test/jdk/java/lang/String/CompactString/CompareTo.java

Print this page

        

*** 26,37 **** import static org.testng.Assert.assertEquals; /* * @test ! * @bug 8077559 ! * @summary Tests Compact String. This one is for String.compareTo. * @run testng/othervm -XX:+CompactStrings CompareTo * @run testng/othervm -XX:-CompactStrings CompareTo */ public class CompareTo extends CompactString { --- 26,38 ---- import static org.testng.Assert.assertEquals; /* * @test ! * @bug 8077559 8137326 ! * @summary Tests Compact String. Verifies the compareTo method for String, ! * StringBuilder and StringBuffer. * @run testng/othervm -XX:+CompactStrings CompareTo * @run testng/othervm -XX:-CompactStrings CompareTo */ public class CompareTo extends CompactString {
*** 89,94 **** --- 90,137 ---- escapeNonASCIIs(data), escapeNonASCIIs(anotherString), source)); }); } + + /* + * Runs the same test with StringBuilder + */ + @Test(dataProvider = "provider") + public void testStringBuilder(String str, String anotherString, int expected) { + StringBuilder another = new StringBuilder(anotherString); + map.get(str) + .forEach( + (source, data) -> { + StringBuilder sb = new StringBuilder(data); + assertEquals( + sb.compareTo(another), + expected, + String.format( + "testing StringBuilder(%s).compareTo(%s), source : %s, ", + escapeNonASCIIs(data), + escapeNonASCIIs(anotherString), + source)); + }); + } + + /* + * Runs the same test with StringBuffer + */ + @Test(dataProvider = "provider") + public void testStringBuffer(String str, String anotherString, int expected) { + StringBuffer another = new StringBuffer(anotherString); + map.get(str) + .forEach( + (source, data) -> { + StringBuffer sb = new StringBuffer(data); + assertEquals( + sb.compareTo(another), + expected, + String.format( + "testing StringBuffer(%s).compareTo(%s), source : %s, ", + escapeNonASCIIs(data), + escapeNonASCIIs(anotherString), + source)); + }); + } }
< prev index next >