|
|
@@ -509,24 +509,47 @@ c*/
|
|
|
|
|
|
@Test
|
|
|
public void testWrap() {
|
|
|
- assertTrue("Hel".contentEquals(StringUtils.wrap("Hel".toCharArray())));
|
|
|
- assertTrue("Hel".contentEquals(StringUtils.wrap("Hello".toCharArray(),0,3)) );
|
|
|
- assertTrue("l".contentEquals(StringUtils.wrap("Hello".toCharArray(),2,3)) );
|
|
|
- assertTrue("llo".contentEquals(StringUtils.wrap("Hello".toCharArray(),2,5)) );
|
|
|
+ assertString("Hel", StringUtils.wrap("Hel".toCharArray()));
|
|
|
+ assertString("Hel", StringUtils.wrap("Hello".toCharArray(),0,3));
|
|
|
+ assertString("l" , StringUtils.wrap("Hello".toCharArray(),2,3));
|
|
|
+ assertString("llo", StringUtils.wrap("Hello".toCharArray(),2,5));
|
|
|
+
|
|
|
+ assertString("ello wo", StringUtils.wrap("Hello world".toCharArray()).subSequence(1, 8) );
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testRepeat() {
|
|
|
- assertTrue("...".contentEquals(StringUtils.repeat(3,'.')));
|
|
|
- assertTrue(".....".contentEquals(StringUtils.repeat(16,'.').subSequence(3, 8)));
|
|
|
-
|
|
|
- assertTrue("rerere".contentEquals(StringUtils.repeat(3,"re")));
|
|
|
-
|
|
|
- assertTrue("arvarvar".contentEquals(StringUtils.repeat(4,"var").subSequence(4, 12)));
|
|
|
- assertTrue("arvarvarv".contentEquals(StringUtils.repeat(5,"var").subSequence(4, 13)));
|
|
|
-
|
|
|
- assertThrows(ArrayIndexOutOfBoundsException.class, ()->{
|
|
|
- StringUtils.repeat(4,"var").subSequence(4, 13).toString();
|
|
|
+ public void testRepeatChar() {
|
|
|
+ assertString("...", StringUtils.repeat(3,'.'));
|
|
|
+ assertString(".....", StringUtils.repeat(16,'.').subSequence(3, 8));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRepeatString() {
|
|
|
+ assertString("rerere", StringUtils.repeat(3,"re"));
|
|
|
+ assertString("arvarvar", StringUtils.repeat(4,"var").subSequence(4, 12));
|
|
|
+ assertString("arvarvarv", StringUtils.repeat(5,"var").subSequence(4, 13));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assertString(String expected, CharSequence value) {
|
|
|
+ assertTrue(expected.contentEquals(value));
|
|
|
+ assertEquals(expected, value.toString());
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.charAt(-1);
|
|
|
+ });
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.charAt(value.length());
|
|
|
+ });
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.charAt(value.length()+1);
|
|
|
+ });
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.subSequence(1, value.length()+2);
|
|
|
+ });
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.subSequence(-1, 2);
|
|
|
+ });
|
|
|
+ assertThrows(IndexOutOfBoundsException.class, ()->{
|
|
|
+ value.subSequence(2, 1);
|
|
|
});
|
|
|
}
|
|
|
|