StringBuilderTest.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18package org.apache.harmony.luni.tests.java.lang;
19
20import dalvik.annotation.TestTargets;
21import dalvik.annotation.TestLevel;
22import dalvik.annotation.TestTargetNew;
23import dalvik.annotation.TestTargetClass;
24
25import junit.framework.TestCase;
26
27import java.io.Serializable;
28import java.util.Arrays;
29
30import org.apache.harmony.testframework.serialization.SerializationTest;
31import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
32
33@TestTargetClass(StringBuilder.class)
34public class StringBuilderTest extends TestCase {
35
36    /**
37     * @tests java.lang.StringBuilder.StringBuilder()
38     */
39    @TestTargetNew(
40        level = TestLevel.COMPLETE,
41        notes = "",
42        method = "StringBuilder",
43        args = {}
44    )
45    public void test_Constructor() {
46        StringBuilder sb = new StringBuilder();
47        assertNotNull(sb);
48        assertEquals(16, sb.capacity());
49    }
50
51    /**
52     * @tests java.lang.StringBuilder.StringBuilder(int)
53     */
54    @TestTargetNew(
55        level = TestLevel.COMPLETE,
56        notes = "",
57        method = "StringBuilder",
58        args = {int.class}
59    )
60    public void test_ConstructorI() {
61        StringBuilder sb = new StringBuilder(24);
62        assertNotNull(sb);
63        assertEquals(24, sb.capacity());
64
65        try {
66            new StringBuilder(-1);
67            fail("no exception");
68        } catch (NegativeArraySizeException e) {
69            // Expected
70        }
71
72        assertNotNull(new StringBuilder(0));
73    }
74
75    /**
76     * @tests java.lang.StringBuilder.StringBuilder(CharSequence)
77     */
78    @TestTargetNew(
79        level = TestLevel.COMPLETE,
80        notes = "",
81        method = "StringBuilder",
82        args = {java.lang.CharSequence.class}
83    )
84    @SuppressWarnings("cast")
85    public void test_ConstructorLjava_lang_CharSequence() {
86        StringBuilder sb = new StringBuilder((CharSequence) "fixture");
87        assertEquals("fixture", sb.toString());
88        assertEquals("fixture".length() + 16, sb.capacity());
89
90        sb = new StringBuilder((CharSequence) new StringBuffer("fixture"));
91        assertEquals("fixture", sb.toString());
92        assertEquals("fixture".length() + 16, sb.capacity());
93
94        try {
95            new StringBuilder((CharSequence) null);
96            fail("no NPE");
97        } catch (NullPointerException e) {
98            // Expected
99        }
100    }
101
102    /**
103     * @tests java.lang.StringBuilder.StringBuilder(String)
104     */
105    @TestTargetNew(
106        level = TestLevel.COMPLETE,
107        notes = "",
108        method = "StringBuilder",
109        args = {java.lang.String.class}
110    )
111    public void test_ConstructorLjava_lang_String() {
112        StringBuilder sb = new StringBuilder("fixture");
113        assertEquals("fixture", sb.toString());
114        assertEquals("fixture".length() + 16, sb.capacity());
115
116        try {
117            new StringBuilder((String) null);
118            fail("no NPE");
119        } catch (NullPointerException e) {
120        }
121    }
122
123    /**
124     * @tests java.lang.StringBuilder.append(boolean)
125     */
126    @TestTargetNew(
127        level = TestLevel.COMPLETE,
128        notes = "",
129        method = "append",
130        args = {boolean.class}
131    )
132    public void test_appendZ() {
133        StringBuilder sb = new StringBuilder();
134        assertSame(sb, sb.append(true));
135        assertEquals("true", sb.toString());
136        sb.setLength(0);
137        assertSame(sb, sb.append(false));
138        assertEquals("false", sb.toString());
139    }
140
141    /**
142     * @tests java.lang.StringBuilder.append(char)
143     */
144    @TestTargetNew(
145        level = TestLevel.COMPLETE,
146        notes = "",
147        method = "append",
148        args = {char.class}
149    )
150    public void test_appendC() {
151        StringBuilder sb = new StringBuilder();
152        assertSame(sb, sb.append('a'));
153        assertEquals("a", sb.toString());
154        sb.setLength(0);
155        assertSame(sb, sb.append('b'));
156        assertEquals("b", sb.toString());
157    }
158
159    /**
160     * @tests java.lang.StringBuilder.append(char[])
161     */
162    @TestTargetNew(
163        level = TestLevel.COMPLETE,
164        notes = "",
165        method = "append",
166        args = {char[].class}
167    )
168    public void test_append$C() {
169        StringBuilder sb = new StringBuilder();
170        assertSame(sb, sb.append(new char[] { 'a', 'b' }));
171        assertEquals("ab", sb.toString());
172        sb.setLength(0);
173        assertSame(sb, sb.append(new char[] { 'c', 'd' }));
174        assertEquals("cd", sb.toString());
175        try {
176            sb.append((char[]) null);
177            fail("no NPE");
178        } catch (NullPointerException e) {
179            // Expected
180        }
181    }
182
183    /**
184     * @tests java.lang.StringBuilder.append(char[], int, int)
185     */
186    @TestTargetNew(
187        level = TestLevel.COMPLETE,
188        notes = "",
189        method = "append",
190        args = {char[].class, int.class, int.class}
191    )
192    public void test_append$CII() {
193        StringBuilder sb = new StringBuilder();
194        assertSame(sb, sb.append(new char[] { 'a', 'b' }, 0, 2));
195        assertEquals("ab", sb.toString());
196        sb.setLength(0);
197        assertSame(sb, sb.append(new char[] { 'c', 'd' }, 0, 2));
198        assertEquals("cd", sb.toString());
199
200        sb.setLength(0);
201        assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, 2));
202        assertEquals("ab", sb.toString());
203
204        sb.setLength(0);
205        assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 2));
206        assertEquals("cd", sb.toString());
207
208        sb.setLength(0);
209        assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 0));
210        assertEquals("", sb.toString());
211
212        try {
213            sb.append((char[]) null, 0, 2);
214            fail("no NPE");
215        } catch (NullPointerException e) {
216            // Expected
217        }
218
219        try {
220            sb.append(new char[] { 'a', 'b', 'c', 'd' }, -1, 2);
221            fail("no IOOBE, negative offset");
222        } catch (IndexOutOfBoundsException e) {
223            // Expected
224        }
225
226        try {
227            sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, -1);
228            fail("no IOOBE, negative length");
229        } catch (IndexOutOfBoundsException e) {
230            // Expected
231        }
232
233        try {
234            sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 3);
235            fail("no IOOBE, offset and length overflow");
236        } catch (IndexOutOfBoundsException e) {
237            // Expected
238        }
239    }
240
241    /**
242     * @tests java.lang.StringBuilder.append(CharSequence)
243     */
244    @TestTargetNew(
245        level = TestLevel.COMPLETE,
246        notes = "",
247        method = "append",
248        args = {java.lang.CharSequence.class}
249    )
250    public void test_appendLjava_lang_CharSequence() {
251        StringBuilder sb = new StringBuilder();
252        assertSame(sb, sb.append((CharSequence) "ab"));
253        assertEquals("ab", sb.toString());
254        sb.setLength(0);
255        assertSame(sb, sb.append((CharSequence) "cd"));
256        assertEquals("cd", sb.toString());
257        sb.setLength(0);
258        assertSame(sb, sb.append((CharSequence) null));
259        assertEquals("null", sb.toString());
260    }
261
262    /**
263     * @tests java.lang.StringBuilder.append(CharSequence, int, int)
264     */
265    @TestTargetNew(
266        level = TestLevel.COMPLETE,
267        notes = "",
268        method = "append",
269        args = {java.lang.CharSequence.class, int.class, int.class}
270    )
271    @SuppressWarnings("cast")
272    public void test_appendLjava_lang_CharSequenceII() {
273        StringBuilder sb = new StringBuilder();
274        assertSame(sb, sb.append((CharSequence) "ab", 0, 2));
275        assertEquals("ab", sb.toString());
276        sb.setLength(0);
277        assertSame(sb, sb.append((CharSequence) "cd", 0, 2));
278        assertEquals("cd", sb.toString());
279        sb.setLength(0);
280        assertSame(sb, sb.append((CharSequence) "abcd", 0, 2));
281        assertEquals("ab", sb.toString());
282        sb.setLength(0);
283        assertSame(sb, sb.append((CharSequence) "abcd", 2, 4));
284        assertEquals("cd", sb.toString());
285        sb.setLength(0);
286        assertSame(sb, sb.append((CharSequence) null, 0, 2));
287        assertEquals("nu", sb.toString());
288
289        try {
290            sb.append((CharSequence) "abcd", -1, 2);
291            fail("IndexOutOfBoundsException was thrown.");
292        } catch(IndexOutOfBoundsException e) {
293            //expected
294        }
295
296        try {
297            sb.append((CharSequence) "abcd", 0, 5);
298            fail("IndexOutOfBoundsException was thrown.");
299        } catch(IndexOutOfBoundsException e) {
300            //expected
301        }
302
303        try {
304            sb.append((CharSequence) "abcd", 2, 1);
305            fail("IndexOutOfBoundsException was thrown.");
306        } catch(IndexOutOfBoundsException e) {
307            //expected
308        }
309    }
310
311    /**
312     * @tests java.lang.StringBuilder.append(double)
313     */
314    @TestTargetNew(
315        level = TestLevel.COMPLETE,
316        notes = "",
317        method = "append",
318        args = {double.class}
319    )
320    public void test_appendD() {
321        StringBuilder sb = new StringBuilder();
322        assertSame(sb, sb.append(1D));
323        assertEquals(String.valueOf(1D), sb.toString());
324        sb.setLength(0);
325        assertSame(sb, sb.append(0D));
326        assertEquals(String.valueOf(0D), sb.toString());
327        sb.setLength(0);
328        assertSame(sb, sb.append(-1D));
329        assertEquals(String.valueOf(-1D), sb.toString());
330        sb.setLength(0);
331        assertSame(sb, sb.append(Double.NaN));
332        assertEquals(String.valueOf(Double.NaN), sb.toString());
333        sb.setLength(0);
334        assertSame(sb, sb.append(Double.NEGATIVE_INFINITY));
335        assertEquals(String.valueOf(Double.NEGATIVE_INFINITY), sb.toString());
336        sb.setLength(0);
337        assertSame(sb, sb.append(Double.POSITIVE_INFINITY));
338        assertEquals(String.valueOf(Double.POSITIVE_INFINITY), sb.toString());
339        sb.setLength(0);
340        assertSame(sb, sb.append(Double.MIN_VALUE));
341        assertEquals(String.valueOf(Double.MIN_VALUE), sb.toString());
342        sb.setLength(0);
343        assertSame(sb, sb.append(Double.MAX_VALUE));
344        assertEquals(String.valueOf(Double.MAX_VALUE), sb.toString());
345    }
346
347    /**
348     * @tests java.lang.StringBuilder.append(float)
349     */
350    @TestTargetNew(
351        level = TestLevel.COMPLETE,
352        notes = "",
353        method = "append",
354        args = {float.class}
355    )
356    public void test_appendF() {
357        StringBuilder sb = new StringBuilder();
358        assertSame(sb, sb.append(1F));
359        assertEquals(String.valueOf(1F), sb.toString());
360        sb.setLength(0);
361        assertSame(sb, sb.append(0F));
362        assertEquals(String.valueOf(0F), sb.toString());
363        sb.setLength(0);
364        assertSame(sb, sb.append(-1F));
365        assertEquals(String.valueOf(-1F), sb.toString());
366        sb.setLength(0);
367        assertSame(sb, sb.append(Float.NaN));
368        assertEquals(String.valueOf(Float.NaN), sb.toString());
369        sb.setLength(0);
370        assertSame(sb, sb.append(Float.NEGATIVE_INFINITY));
371        assertEquals(String.valueOf(Float.NEGATIVE_INFINITY), sb.toString());
372        sb.setLength(0);
373        assertSame(sb, sb.append(Float.POSITIVE_INFINITY));
374        assertEquals(String.valueOf(Float.POSITIVE_INFINITY), sb.toString());
375        sb.setLength(0);
376        assertSame(sb, sb.append(Float.MIN_VALUE));
377        assertEquals(String.valueOf(Float.MIN_VALUE), sb.toString());
378        sb.setLength(0);
379        assertSame(sb, sb.append(Float.MAX_VALUE));
380        assertEquals(String.valueOf(Float.MAX_VALUE), sb.toString());
381    }
382
383    /**
384     * @tests java.lang.StringBuilder.append(int)
385     */
386    @TestTargetNew(
387        level = TestLevel.COMPLETE,
388        notes = "",
389        method = "append",
390        args = {int.class}
391    )
392    public void test_appendI() {
393        StringBuilder sb = new StringBuilder();
394        assertSame(sb, sb.append(1));
395        assertEquals(String.valueOf(1), sb.toString());
396        sb.setLength(0);
397        assertSame(sb, sb.append(0));
398        assertEquals(String.valueOf(0), sb.toString());
399        sb.setLength(0);
400        assertSame(sb, sb.append(-1));
401        assertEquals(String.valueOf(-1), sb.toString());
402        sb.setLength(0);
403        assertSame(sb, sb.append(Integer.MIN_VALUE));
404        assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
405        sb.setLength(0);
406        assertSame(sb, sb.append(Integer.MAX_VALUE));
407        assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
408    }
409
410    /**
411     * @tests java.lang.StringBuilder.append(long)
412     */
413    @TestTargetNew(
414        level = TestLevel.COMPLETE,
415        notes = "",
416        method = "append",
417        args = {long.class}
418    )
419    public void test_appendL() {
420        StringBuilder sb = new StringBuilder();
421        assertSame(sb, sb.append(1L));
422        assertEquals(String.valueOf(1L), sb.toString());
423        sb.setLength(0);
424        assertSame(sb, sb.append(0L));
425        assertEquals(String.valueOf(0L), sb.toString());
426        sb.setLength(0);
427        assertSame(sb, sb.append(-1L));
428        assertEquals(String.valueOf(-1L), sb.toString());
429        sb.setLength(0);
430        assertSame(sb, sb.append(Integer.MIN_VALUE));
431        assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
432        sb.setLength(0);
433        assertSame(sb, sb.append(Integer.MAX_VALUE));
434        assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
435    }
436
437    /**
438     * @tests java.lang.StringBuilder.append(Object)'
439     */
440    @TestTargetNew(
441        level = TestLevel.COMPLETE,
442        notes = "",
443        method = "append",
444        args = {java.lang.Object.class}
445    )
446    public void test_appendLjava_lang_Object() {
447        StringBuilder sb = new StringBuilder();
448        assertSame(sb, sb.append(Fixture.INSTANCE));
449        assertEquals(Fixture.INSTANCE.toString(), sb.toString());
450
451        sb.setLength(0);
452        assertSame(sb, sb.append((Object) null));
453        assertEquals("null", sb.toString());
454    }
455
456    /**
457     * @tests java.lang.StringBuilder.append(String)
458     */
459    @TestTargetNew(
460        level = TestLevel.COMPLETE,
461        notes = "",
462        method = "append",
463        args = {java.lang.String.class}
464    )
465    public void test_appendLjava_lang_String() {
466        StringBuilder sb = new StringBuilder();
467        assertSame(sb, sb.append("ab"));
468        assertEquals("ab", sb.toString());
469        sb.setLength(0);
470        assertSame(sb, sb.append("cd"));
471        assertEquals("cd", sb.toString());
472        sb.setLength(0);
473        assertSame(sb, sb.append((String) null));
474        assertEquals("null", sb.toString());
475    }
476
477    /**
478     * @tests java.lang.StringBuilder.append(StringBuffer)
479     */
480    @TestTargetNew(
481        level = TestLevel.COMPLETE,
482        notes = "",
483        method = "append",
484        args = {java.lang.StringBuffer.class}
485    )
486    public void test_appendLjava_lang_StringBuffer() {
487        StringBuilder sb = new StringBuilder();
488        assertSame(sb, sb.append(new StringBuffer("ab")));
489        assertEquals("ab", sb.toString());
490        sb.setLength(0);
491        assertSame(sb, sb.append(new StringBuffer("cd")));
492        assertEquals("cd", sb.toString());
493        sb.setLength(0);
494        assertSame(sb, sb.append((StringBuffer) null));
495        assertEquals("null", sb.toString());
496    }
497
498    /**
499     * @tests java.lang.StringBuilder.appendCodePoint(int)'
500     */
501    @TestTargetNew(
502        level = TestLevel.COMPLETE,
503        notes = "",
504        method = "appendCodePoint",
505        args = {int.class}
506    )
507    public void test_appendCodePointI() {
508        StringBuilder sb = new StringBuilder();
509        sb.appendCodePoint(0x10000);
510        assertEquals("\uD800\uDC00", sb.toString());
511        sb.append("fixture");
512        assertEquals("\uD800\uDC00fixture", sb.toString());
513        sb.appendCodePoint(0x00010FFFF);
514        assertEquals("\uD800\uDC00fixture\uDBFF\uDFFF", sb.toString());
515    }
516
517    /**
518     * @tests java.lang.StringBuilder.capacity()'
519     */
520    @TestTargetNew(
521        level = TestLevel.COMPLETE,
522        notes = "",
523        method = "capacity",
524        args = {}
525    )
526    public void test_capacity() {
527        StringBuilder sb = new StringBuilder();
528        assertEquals(16, sb.capacity());
529        sb.append("0123456789ABCDEF0123456789ABCDEF");
530        assertTrue(sb.capacity() > 16);
531    }
532
533    /**
534     * @tests java.lang.StringBuilder.charAt(int)'
535     */
536    @TestTargetNew(
537        level = TestLevel.COMPLETE,
538        notes = "",
539        method = "charAt",
540        args = {int.class}
541    )
542    public void test_charAtI() {
543        final String fixture = "0123456789";
544        StringBuilder sb = new StringBuilder(fixture);
545        for (int i = 0; i < fixture.length(); i++) {
546            assertEquals((char) ('0' + i), sb.charAt(i));
547        }
548
549        try {
550            sb.charAt(-1);
551            fail("no IOOBE, negative index");
552        } catch (IndexOutOfBoundsException e) {
553            // Expected
554        }
555
556        try {
557            sb.charAt(fixture.length());
558            fail("no IOOBE, equal to length");
559        } catch (IndexOutOfBoundsException e) {
560        }
561
562        try {
563            sb.charAt(fixture.length() + 1);
564            fail("no IOOBE, greater than length");
565        } catch (IndexOutOfBoundsException e) {
566        }
567    }
568
569    /**
570     * @tests java.lang.StringBuilder.codePointAt(int)
571     */
572    @TestTargetNew(
573        level = TestLevel.COMPLETE,
574        notes = "",
575        method = "codePointAt",
576        args = {int.class}
577    )
578    public void test_codePointAtI() {
579        StringBuilder sb = new StringBuilder("abc");
580        assertEquals('a', sb.codePointAt(0));
581        assertEquals('b', sb.codePointAt(1));
582        assertEquals('c', sb.codePointAt(2));
583
584        sb = new StringBuilder("\uD800\uDC00");
585        assertEquals(0x10000, sb.codePointAt(0));
586        assertEquals('\uDC00', sb.codePointAt(1));
587
588        sb = new StringBuilder();
589        sb.append("abc");
590        try {
591            sb.codePointAt(-1);
592            fail("No IOOBE on negative index.");
593        } catch (IndexOutOfBoundsException e) {
594
595        }
596
597        try {
598            sb.codePointAt(sb.length());
599            fail("No IOOBE on index equal to length.");
600        } catch (IndexOutOfBoundsException e) {
601
602        }
603
604        try {
605            sb.codePointAt(sb.length() + 1);
606            fail("No IOOBE on index greater than length.");
607        } catch (IndexOutOfBoundsException e) {
608
609        }
610    }
611
612    /**
613     * @tests java.lang.StringBuilder.codePointBefore(int)
614     */
615    @TestTargetNew(
616        level = TestLevel.COMPLETE,
617        notes = "",
618        method = "codePointBefore",
619        args = {int.class}
620    )
621    public void test_codePointBeforeI() {
622        StringBuilder sb = new StringBuilder("abc");
623        assertEquals('a', sb.codePointBefore(1));
624        assertEquals('b', sb.codePointBefore(2));
625        assertEquals('c', sb.codePointBefore(3));
626
627        sb = new StringBuilder("\uD800\uDC00");
628        assertEquals(0x10000, sb.codePointBefore(2));
629        assertEquals('\uD800', sb.codePointBefore(1));
630
631        sb = new StringBuilder();
632        sb.append("abc");
633
634        try {
635            sb.codePointBefore(0);
636            fail("No IOOBE on zero index.");
637        } catch (IndexOutOfBoundsException e) {
638
639        }
640
641        try {
642            sb.codePointBefore(-1);
643            fail("No IOOBE on negative index.");
644        } catch (IndexOutOfBoundsException e) {
645
646        }
647
648        try {
649            sb.codePointBefore(sb.length() + 1);
650            fail("No IOOBE on index greater than length.");
651        } catch (IndexOutOfBoundsException e) {
652
653        }
654    }
655
656    /**
657     * @tests java.lang.StringBuilder.codePointCount(int, int)
658     */
659    @TestTargetNew(
660        level = TestLevel.COMPLETE,
661        notes = "",
662        method = "codePointCount",
663        args = {int.class, int.class}
664    )
665    public void test_codePointCountII() {
666        assertEquals(1, new StringBuilder("\uD800\uDC00").codePointCount(0, 2));
667        assertEquals(1, new StringBuilder("\uD800\uDC01").codePointCount(0, 2));
668        assertEquals(1, new StringBuilder("\uD801\uDC01").codePointCount(0, 2));
669        assertEquals(1, new StringBuilder("\uDBFF\uDFFF").codePointCount(0, 2));
670
671        assertEquals(3, new StringBuilder("a\uD800\uDC00b").codePointCount(0, 4));
672        assertEquals(4, new StringBuilder("a\uD800\uDC00b\uD800").codePointCount(0, 5));
673
674        StringBuilder sb = new StringBuilder();
675        sb.append("abc");
676        try {
677            sb.codePointCount(-1, 2);
678            fail("No IOOBE for negative begin index.");
679        } catch (IndexOutOfBoundsException e) {
680
681        }
682
683        try {
684            sb.codePointCount(0, 4);
685            fail("No IOOBE for end index that's too large.");
686        } catch (IndexOutOfBoundsException e) {
687
688        }
689
690        try {
691            sb.codePointCount(3, 2);
692            fail("No IOOBE for begin index larger than end index.");
693        } catch (IndexOutOfBoundsException e) {
694
695        }
696    }
697
698    /**
699     * @tests java.lang.StringBuilder.delete(int, int)
700     */
701    @TestTargetNew(
702        level = TestLevel.COMPLETE,
703        notes = "",
704        method = "delete",
705        args = {int.class, int.class}
706    )
707    public void test_deleteII() {
708        final String fixture = "0123456789";
709        StringBuilder sb = new StringBuilder(fixture);
710        assertSame(sb, sb.delete(0, 0));
711        assertEquals(fixture, sb.toString());
712        assertSame(sb, sb.delete(5, 5));
713        assertEquals(fixture, sb.toString());
714        assertSame(sb, sb.delete(0, 1));
715        assertEquals("123456789", sb.toString());
716        assertEquals(9, sb.length());
717        assertSame(sb, sb.delete(0, sb.length()));
718        assertEquals("", sb.toString());
719        assertEquals(0, sb.length());
720
721        sb = new StringBuilder(fixture);
722        assertSame(sb, sb.delete(0, 11));
723        assertEquals("", sb.toString());
724        assertEquals(0, sb.length());
725
726        try {
727            new StringBuilder(fixture).delete(-1, 2);
728            fail("no SIOOBE, negative start");
729        } catch (StringIndexOutOfBoundsException e) {
730            // Expected
731        }
732
733        try {
734            new StringBuilder(fixture).delete(11, 12);
735            fail("no SIOOBE, start too far");
736        } catch (StringIndexOutOfBoundsException e) {
737            // Expected
738        }
739
740        try {
741            new StringBuilder(fixture).delete(13, 12);
742            fail("no SIOOBE, start larger than end");
743        } catch (StringIndexOutOfBoundsException e) {
744            // Expected
745        }
746    }
747
748    /**
749     * @tests java.lang.StringBuilder.deleteCharAt(int)
750     */
751    @TestTargetNew(
752        level = TestLevel.COMPLETE,
753        notes = "",
754        method = "deleteCharAt",
755        args = {int.class}
756    )
757    public void test_deleteCharAtI() {
758        final String fixture = "0123456789";
759        StringBuilder sb = new StringBuilder(fixture);
760        assertSame(sb, sb.deleteCharAt(0));
761        assertEquals("123456789", sb.toString());
762        assertEquals(9, sb.length());
763        sb = new StringBuilder(fixture);
764        assertSame(sb, sb.deleteCharAt(5));
765        assertEquals("012346789", sb.toString());
766        assertEquals(9, sb.length());
767        sb = new StringBuilder(fixture);
768        assertSame(sb, sb.deleteCharAt(9));
769        assertEquals("012345678", sb.toString());
770        assertEquals(9, sb.length());
771
772        try {
773            new StringBuilder(fixture).deleteCharAt(-1);
774            fail("no SIOOBE, negative index");
775        } catch (StringIndexOutOfBoundsException e) {
776            // Expected
777        }
778
779        try {
780            new StringBuilder(fixture).deleteCharAt(fixture.length());
781            fail("no SIOOBE, index equals length");
782        } catch (StringIndexOutOfBoundsException e) {
783            // Expected
784        }
785
786        try {
787            new StringBuilder(fixture).deleteCharAt(fixture.length() + 1);
788            fail("no SIOOBE, index exceeds length");
789        } catch (StringIndexOutOfBoundsException e) {
790            // Expected
791        }
792    }
793
794    /**
795     * @tests java.lang.StringBuilder.ensureCapacity(int)'
796     */
797    @TestTargetNew(
798        level = TestLevel.COMPLETE,
799        notes = "",
800        method = "ensureCapacity",
801        args = {int.class}
802    )
803    public void test_ensureCapacityI() {
804        StringBuilder sb = new StringBuilder(5);
805        assertEquals(5, sb.capacity());
806        sb.ensureCapacity(10);
807        assertEquals(12, sb.capacity());
808        sb.ensureCapacity(26);
809        assertEquals(26, sb.capacity());
810        sb.ensureCapacity(55);
811        assertEquals(55, sb.capacity());
812    }
813
814    /**
815     * @tests java.lang.StringBuilder.getChars(int, int, char[], int)'
816     */
817    @TestTargetNew(
818        level = TestLevel.COMPLETE,
819        notes = "",
820        method = "getChars",
821        args = {int.class, int.class, char[].class, int.class}
822    )
823    public void test_getCharsII$CI() {
824        final String fixture = "0123456789";
825        StringBuilder sb = new StringBuilder(fixture);
826        char[] dst = new char[10];
827        sb.getChars(0, 10, dst, 0);
828        assertTrue(Arrays.equals(fixture.toCharArray(), dst));
829
830        Arrays.fill(dst, '\0');
831        sb.getChars(0, 5, dst, 0);
832        char[] fixtureChars = new char[10];
833        fixture.getChars(0, 5, fixtureChars, 0);
834        assertTrue(Arrays.equals(fixtureChars, dst));
835
836        Arrays.fill(dst, '\0');
837        Arrays.fill(fixtureChars, '\0');
838        sb.getChars(0, 5, dst, 5);
839        fixture.getChars(0, 5, fixtureChars, 5);
840        assertTrue(Arrays.equals(fixtureChars, dst));
841
842        Arrays.fill(dst, '\0');
843        Arrays.fill(fixtureChars, '\0');
844        sb.getChars(5, 10, dst, 1);
845        fixture.getChars(5, 10, fixtureChars, 1);
846        assertTrue(Arrays.equals(fixtureChars, dst));
847
848        try {
849            sb.getChars(0, 10, null, 0);
850            fail("no NPE");
851        } catch (NullPointerException e) {
852            // Expected
853        }
854
855        try {
856            sb.getChars(-1, 10, dst, 0);
857            fail("no IOOBE, srcBegin negative");
858        } catch (IndexOutOfBoundsException e) {
859            // Expected
860        }
861
862        try {
863            sb.getChars(0, 10, dst, -1);
864            fail("no IOOBE, dstBegin negative");
865        } catch (IndexOutOfBoundsException e) {
866            // Expected
867        }
868
869        try {
870            sb.getChars(5, 4, dst, 0);
871            fail("no IOOBE, srcBegin > srcEnd");
872        } catch (IndexOutOfBoundsException e) {
873            // Expected
874        }
875
876        try {
877            sb.getChars(0, 11, dst, 0);
878            fail("no IOOBE, srcEnd > length");
879        } catch (IndexOutOfBoundsException e) {
880            // Expected
881        }
882
883        try {
884            sb.getChars(0, 10, dst, 5);
885            fail("no IOOBE, dstBegin and src size too large for what's left in dst");
886        } catch (IndexOutOfBoundsException e) {
887            // Expected
888        }
889    }
890
891    /**
892     * @tests java.lang.StringBuilder.indexOf(String)
893     */
894    @TestTargetNew(
895        level = TestLevel.COMPLETE,
896        notes = "",
897        method = "indexOf",
898        args = {java.lang.String.class}
899    )
900    public void test_indexOfLjava_lang_String() {
901        final String fixture = "0123456789";
902        StringBuilder sb = new StringBuilder(fixture);
903        assertEquals(0, sb.indexOf("0"));
904        assertEquals(0, sb.indexOf("012"));
905        assertEquals(-1, sb.indexOf("02"));
906        assertEquals(8, sb.indexOf("89"));
907
908        try {
909            sb.indexOf(null);
910            fail("no NPE");
911        } catch (NullPointerException e) {
912            // Expected
913        }
914    }
915
916    /**
917     * @tests java.lang.StringBuilder.indexOf(String, int)
918     */
919    @TestTargetNew(
920        level = TestLevel.COMPLETE,
921        notes = "",
922        method = "indexOf",
923        args = {java.lang.String.class, int.class}
924    )
925    public void test_IndexOfStringInt() {
926        final String fixture = "0123456789";
927        StringBuilder sb = new StringBuilder(fixture);
928        assertEquals(0, sb.indexOf("0"));
929        assertEquals(0, sb.indexOf("012"));
930        assertEquals(-1, sb.indexOf("02"));
931        assertEquals(8, sb.indexOf("89"));
932
933        assertEquals(0, sb.indexOf("0"), 0);
934        assertEquals(0, sb.indexOf("012"), 0);
935        assertEquals(-1, sb.indexOf("02"), 0);
936        assertEquals(8, sb.indexOf("89"), 0);
937
938        assertEquals(-1, sb.indexOf("0"), 5);
939        assertEquals(-1, sb.indexOf("012"), 5);
940        assertEquals(-1, sb.indexOf("02"), 0);
941        assertEquals(8, sb.indexOf("89"), 5);
942
943        try {
944            sb.indexOf(null, 0);
945            fail("no NPE");
946        } catch (NullPointerException e) {
947            // Expected
948        }
949    }
950
951    /**
952     * @tests java.lang.StringBuilder.insert(int, boolean)
953     */
954    @TestTargetNew(
955        level = TestLevel.COMPLETE,
956        notes = "",
957        method = "insert",
958        args = {int.class, boolean.class}
959    )
960    public void test_insertIZ() {
961        final String fixture = "0000";
962        StringBuilder sb = new StringBuilder(fixture);
963        assertSame(sb, sb.insert(0, true));
964        assertEquals("true0000", sb.toString());
965        assertEquals(8, sb.length());
966
967        sb = new StringBuilder(fixture);
968        assertSame(sb, sb.insert(0, false));
969        assertEquals("false0000", sb.toString());
970        assertEquals(9, sb.length());
971
972        sb = new StringBuilder(fixture);
973        assertSame(sb, sb.insert(2, false));
974        assertEquals("00false00", sb.toString());
975        assertEquals(9, sb.length());
976
977        sb = new StringBuilder(fixture);
978        assertSame(sb, sb.insert(4, false));
979        assertEquals("0000false", sb.toString());
980        assertEquals(9, sb.length());
981
982        try {
983            sb = new StringBuilder(fixture);
984            sb.insert(-1, false);
985            fail("no SIOOBE, negative index");
986        } catch (StringIndexOutOfBoundsException e) {
987            // Expected
988        }
989
990        try {
991            sb = new StringBuilder(fixture);
992            sb.insert(5, false);
993            fail("no SIOOBE, index too large index");
994        } catch (StringIndexOutOfBoundsException e) {
995            // Expected
996        }
997    }
998
999    /**
1000     * @tests java.lang.StringBuilder.insert(int, char)
1001     */
1002    @TestTargetNew(
1003        level = TestLevel.PARTIAL_COMPLETE,
1004        notes = "IndexOutOfBoundsException is not verified.",
1005        method = "insert",
1006        args = {int.class, char.class}
1007    )
1008    public void test_insertIC() {
1009        final String fixture = "0000";
1010        StringBuilder sb = new StringBuilder(fixture);
1011        assertSame(sb, sb.insert(0, 'a'));
1012        assertEquals("a0000", sb.toString());
1013        assertEquals(5, sb.length());
1014
1015        sb = new StringBuilder(fixture);
1016        assertSame(sb, sb.insert(0, 'b'));
1017        assertEquals("b0000", sb.toString());
1018        assertEquals(5, sb.length());
1019
1020        sb = new StringBuilder(fixture);
1021        assertSame(sb, sb.insert(2, 'b'));
1022        assertEquals("00b00", sb.toString());
1023        assertEquals(5, sb.length());
1024
1025        sb = new StringBuilder(fixture);
1026        assertSame(sb, sb.insert(4, 'b'));
1027        assertEquals("0000b", sb.toString());
1028        assertEquals(5, sb.length());
1029
1030        // FIXME this fails on Sun JRE 5.0_5
1031//        try {
1032//            sb = new StringBuilder(fixture);
1033//            sb.insert(-1, 'a');
1034//            fail("no SIOOBE, negative index");
1035//        } catch (StringIndexOutOfBoundsException e) {
1036//            // Expected
1037//        }
1038
1039        /*
1040         * FIXME This fails on Sun JRE 5.0_5, but that seems like a bug, since
1041         * the 'insert(int, char[]) behaves this way.
1042         */
1043//        try {
1044//            sb = new StringBuilder(fixture);
1045//            sb.insert(5, 'a');
1046//            fail("no SIOOBE, index too large index");
1047//        } catch (StringIndexOutOfBoundsException e) {
1048//            // Expected
1049//        }
1050    }
1051
1052    /**
1053     * @tests java.lang.StringBuilder.insert(int, char)
1054     */
1055    @TestTargetNew(
1056        level = TestLevel.PARTIAL_COMPLETE,
1057        notes = "Verifies ArrayIndexOutOfBoundsException.",
1058        method = "insert",
1059        args = {int.class, char.class}
1060    )
1061    public void test_insertIC_2() {
1062        StringBuilder obj = new StringBuilder();
1063        try {
1064            obj.insert(-1, '?');
1065            fail("ArrayIndexOutOfBoundsException expected");
1066        } catch (ArrayIndexOutOfBoundsException e) {
1067            // expected
1068        }
1069    }
1070
1071    /**
1072     * @tests java.lang.StringBuilder.insert(int, char[])'
1073     */
1074    @TestTargetNew(
1075        level = TestLevel.COMPLETE,
1076        notes = "",
1077        method = "insert",
1078        args = {int.class, char[].class}
1079    )
1080    public void test_insertI$C() {
1081        final String fixture = "0000";
1082        StringBuilder sb = new StringBuilder(fixture);
1083        assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }));
1084        assertEquals("ab0000", sb.toString());
1085        assertEquals(6, sb.length());
1086
1087        sb = new StringBuilder(fixture);
1088        assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }));
1089        assertEquals("00ab00", sb.toString());
1090        assertEquals(6, sb.length());
1091
1092        sb = new StringBuilder(fixture);
1093        assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }));
1094        assertEquals("0000ab", sb.toString());
1095        assertEquals(6, sb.length());
1096
1097        /*
1098         * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
1099         * undocumented. The assumption is that this method behaves like
1100         * String.valueOf(char[]), which does throw a NPE too, but that is also
1101         * undocumented.
1102         */
1103
1104        try {
1105            sb.insert(0, (char[]) null);
1106            fail("no NPE");
1107        } catch (NullPointerException e) {
1108            // Expected
1109        }
1110
1111        try {
1112            sb = new StringBuilder(fixture);
1113            sb.insert(-1, new char[] { 'a', 'b' });
1114            fail("no SIOOBE, negative index");
1115        } catch (StringIndexOutOfBoundsException e) {
1116            // Expected
1117        }
1118
1119        try {
1120            sb = new StringBuilder(fixture);
1121            sb.insert(5, new char[] { 'a', 'b' });
1122            fail("no SIOOBE, index too large index");
1123        } catch (StringIndexOutOfBoundsException e) {
1124            // Expected
1125        }
1126    }
1127
1128    /**
1129     * @tests java.lang.StringBuilder.insert(int, char[], int, int)
1130     */
1131    @TestTargetNew(
1132        level = TestLevel.COMPLETE,
1133        notes = "",
1134        method = "insert",
1135        args = {int.class, char[].class, int.class, int.class}
1136    )
1137    public void test_insertI$CII() {
1138        final String fixture = "0000";
1139        StringBuilder sb = new StringBuilder(fixture);
1140        assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 2));
1141        assertEquals("ab0000", sb.toString());
1142        assertEquals(6, sb.length());
1143
1144        sb = new StringBuilder(fixture);
1145        assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 1));
1146        assertEquals("a0000", sb.toString());
1147        assertEquals(5, sb.length());
1148
1149        sb = new StringBuilder(fixture);
1150        assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 2));
1151        assertEquals("00ab00", sb.toString());
1152        assertEquals(6, sb.length());
1153
1154        sb = new StringBuilder(fixture);
1155        assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 1));
1156        assertEquals("00a00", sb.toString());
1157        assertEquals(5, sb.length());
1158
1159        sb = new StringBuilder(fixture);
1160        assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 2));
1161        assertEquals("0000ab", sb.toString());
1162        assertEquals(6, sb.length());
1163
1164        sb = new StringBuilder(fixture);
1165        assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 1));
1166        assertEquals("0000a", sb.toString());
1167        assertEquals(5, sb.length());
1168
1169        /*
1170         * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
1171         * undocumented. The assumption is that this method behaves like
1172         * String.valueOf(char[]), which does throw a NPE too, but that is also
1173         * undocumented.
1174         */
1175
1176        try {
1177            sb.insert(0, (char[]) null, 0, 2);
1178            fail("no NPE");
1179        } catch (NullPointerException e) {
1180            // Expected
1181        }
1182
1183        try {
1184            sb = new StringBuilder(fixture);
1185            sb.insert(-1, new char[] { 'a', 'b' }, 0, 2);
1186            fail("no SIOOBE, negative index");
1187        } catch (StringIndexOutOfBoundsException e) {
1188            // Expected
1189        }
1190
1191        try {
1192            sb = new StringBuilder(fixture);
1193            sb.insert(5, new char[] { 'a', 'b' }, 0, 2);
1194            fail("no SIOOBE, index too large index");
1195        } catch (StringIndexOutOfBoundsException e) {
1196            // Expected
1197        }
1198
1199        try {
1200            sb = new StringBuilder(fixture);
1201            sb.insert(5, new char[] { 'a', 'b' }, -1, 2);
1202            fail("no SIOOBE, negative offset");
1203        } catch (StringIndexOutOfBoundsException e) {
1204            // Expected
1205        }
1206
1207        try {
1208            sb = new StringBuilder(fixture);
1209            sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
1210            fail("no SIOOBE, negative length");
1211        } catch (StringIndexOutOfBoundsException e) {
1212            // Expected
1213        }
1214
1215        try {
1216            sb = new StringBuilder(fixture);
1217            sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
1218            fail("no SIOOBE, too long");
1219        } catch (StringIndexOutOfBoundsException e) {
1220            // Expected
1221        }
1222    }
1223
1224    /**
1225     * @tests java.lang.StringBuilder.insert(int, CharSequence)
1226     */
1227    @TestTargetNew(
1228        level = TestLevel.COMPLETE,
1229        notes = "",
1230        method = "insert",
1231        args = {int.class, java.lang.CharSequence.class}
1232    )
1233    public void test_insertILjava_lang_CharSequence() {
1234        final String fixture = "0000";
1235        StringBuilder sb = new StringBuilder(fixture);
1236        assertSame(sb, sb.insert(0, (CharSequence) "ab"));
1237        assertEquals("ab0000", sb.toString());
1238        assertEquals(6, sb.length());
1239
1240        sb = new StringBuilder(fixture);
1241        assertSame(sb, sb.insert(2, (CharSequence) "ab"));
1242        assertEquals("00ab00", sb.toString());
1243        assertEquals(6, sb.length());
1244
1245        sb = new StringBuilder(fixture);
1246        assertSame(sb, sb.insert(4, (CharSequence) "ab"));
1247        assertEquals("0000ab", sb.toString());
1248        assertEquals(6, sb.length());
1249
1250        sb = new StringBuilder(fixture);
1251        assertSame(sb, sb.insert(4, (CharSequence) null));
1252        assertEquals("0000null", sb.toString());
1253        assertEquals(8, sb.length());
1254
1255        try {
1256            sb = new StringBuilder(fixture);
1257            sb.insert(-1, (CharSequence) "ab");
1258            fail("no IOOBE, negative index");
1259        } catch (IndexOutOfBoundsException e) {
1260            // Expected
1261        }
1262
1263        try {
1264            sb = new StringBuilder(fixture);
1265            sb.insert(5, (CharSequence) "ab");
1266            fail("no IOOBE, index too large index");
1267        } catch (IndexOutOfBoundsException e) {
1268            // Expected
1269        }
1270    }
1271
1272    /**
1273     * @tests java.lang.StringBuilder.insert(int, CharSequence, int, int)
1274     */
1275    @TestTargetNew(
1276        level = TestLevel.COMPLETE,
1277        notes = "",
1278        method = "insert",
1279        args = {int.class, java.lang.CharSequence.class, int.class, int.class}
1280    )
1281    @SuppressWarnings("cast")
1282    public void test_insertILjava_lang_CharSequenceII() {
1283        final String fixture = "0000";
1284        StringBuilder sb = new StringBuilder(fixture);
1285        assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 2));
1286        assertEquals("ab0000", sb.toString());
1287        assertEquals(6, sb.length());
1288
1289        sb = new StringBuilder(fixture);
1290        assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 1));
1291        assertEquals("a0000", sb.toString());
1292        assertEquals(5, sb.length());
1293
1294        sb = new StringBuilder(fixture);
1295        assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 2));
1296        assertEquals("00ab00", sb.toString());
1297        assertEquals(6, sb.length());
1298
1299        sb = new StringBuilder(fixture);
1300        assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 1));
1301        assertEquals("00a00", sb.toString());
1302        assertEquals(5, sb.length());
1303
1304        sb = new StringBuilder(fixture);
1305        assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 2));
1306        assertEquals("0000ab", sb.toString());
1307        assertEquals(6, sb.length());
1308
1309        sb = new StringBuilder(fixture);
1310        assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 1));
1311        assertEquals("0000a", sb.toString());
1312        assertEquals(5, sb.length());
1313
1314        sb = new StringBuilder(fixture);
1315        assertSame(sb, sb.insert(4, (CharSequence) null, 0, 2));
1316        assertEquals("0000nu", sb.toString());
1317        assertEquals(6, sb.length());
1318
1319        try {
1320            sb = new StringBuilder(fixture);
1321            sb.insert(-1, (CharSequence) "ab", 0, 2);
1322            fail("no IOOBE, negative index");
1323        } catch (IndexOutOfBoundsException e) {
1324            // Expected
1325        }
1326
1327        try {
1328            sb = new StringBuilder(fixture);
1329            sb.insert(5, (CharSequence) "ab", 0, 2);
1330            fail("no IOOBE, index too large index");
1331        } catch (IndexOutOfBoundsException e) {
1332            // Expected
1333        }
1334
1335        try {
1336            sb = new StringBuilder(fixture);
1337            sb.insert(5, (CharSequence) "ab", -1, 2);
1338            fail("no IOOBE, negative offset");
1339        } catch (IndexOutOfBoundsException e) {
1340            // Expected
1341        }
1342
1343        try {
1344            sb = new StringBuilder(fixture);
1345            sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
1346            fail("no IOOBE, negative length");
1347        } catch (IndexOutOfBoundsException e) {
1348            // Expected
1349        }
1350
1351        try {
1352            sb = new StringBuilder(fixture);
1353            sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
1354            fail("no IOOBE, too long");
1355        } catch (IndexOutOfBoundsException e) {
1356            // Expected
1357        }
1358    }
1359
1360    /**
1361     * @tests java.lang.StringBuilder.insert(int, double)
1362     */
1363    @TestTargetNew(
1364        level = TestLevel.COMPLETE,
1365        notes = "",
1366        method = "insert",
1367        args = {int.class, double.class}
1368    )
1369    public void test_insertID() {
1370        final String fixture = "0000";
1371        StringBuilder sb = new StringBuilder(fixture);
1372        assertSame(sb, sb.insert(0, -1D));
1373        assertEquals("-1.00000", sb.toString());
1374        assertEquals(8, sb.length());
1375
1376        sb = new StringBuilder(fixture);
1377        assertSame(sb, sb.insert(0, 0D));
1378        assertEquals("0.00000", sb.toString());
1379        assertEquals(7, sb.length());
1380
1381        sb = new StringBuilder(fixture);
1382        assertSame(sb, sb.insert(2, 1D));
1383        assertEquals("001.000", sb.toString());
1384        assertEquals(7, sb.length());
1385
1386        sb = new StringBuilder(fixture);
1387        assertSame(sb, sb.insert(4, 2D));
1388        assertEquals("00002.0", sb.toString());
1389        assertEquals(7, sb.length());
1390
1391        try {
1392            sb = new StringBuilder(fixture);
1393            sb.insert(-1, 1D);
1394            fail("no IOOBE, negative index");
1395        } catch (IndexOutOfBoundsException e) {
1396            // Expected
1397        }
1398
1399        try {
1400            sb = new StringBuilder(fixture);
1401            sb.insert(5, 1D);
1402            fail("no IOOBE, index too large index");
1403        } catch (IndexOutOfBoundsException e) {
1404            // Expected
1405        }
1406    }
1407
1408    /**
1409     * @tests java.lang.StringBuilder.insert(int, float)
1410     */
1411    @TestTargetNew(
1412        level = TestLevel.COMPLETE,
1413        notes = "",
1414        method = "insert",
1415        args = {int.class, float.class}
1416    )
1417    public void test_insertIF() {
1418        final String fixture = "0000";
1419        StringBuilder sb = new StringBuilder(fixture);
1420        assertSame(sb, sb.insert(0, -1F));
1421        assertEquals("-1.00000", sb.toString());
1422        assertEquals(8, sb.length());
1423
1424        sb = new StringBuilder(fixture);
1425        assertSame(sb, sb.insert(0, 0F));
1426        assertEquals("0.00000", sb.toString());
1427        assertEquals(7, sb.length());
1428
1429        sb = new StringBuilder(fixture);
1430        assertSame(sb, sb.insert(2, 1F));
1431        assertEquals("001.000", sb.toString());
1432        assertEquals(7, sb.length());
1433
1434        sb = new StringBuilder(fixture);
1435        assertSame(sb, sb.insert(4, 2F));
1436        assertEquals("00002.0", sb.toString());
1437        assertEquals(7, sb.length());
1438
1439        try {
1440            sb = new StringBuilder(fixture);
1441            sb.insert(-1, 1F);
1442            fail("no IOOBE, negative index");
1443        } catch (IndexOutOfBoundsException e) {
1444            // Expected
1445        }
1446
1447        try {
1448            sb = new StringBuilder(fixture);
1449            sb.insert(5, 1F);
1450            fail("no IOOBE, index too large index");
1451        } catch (IndexOutOfBoundsException e) {
1452            // Expected
1453        }
1454    }
1455
1456    /**
1457     * @tests java.lang.StringBuilder.insert(int, int)
1458     */
1459    @TestTargetNew(
1460        level = TestLevel.COMPLETE,
1461        notes = "",
1462        method = "insert",
1463        args = {int.class, int.class}
1464    )
1465    public void test_insertII() {
1466        final String fixture = "0000";
1467        StringBuilder sb = new StringBuilder(fixture);
1468        assertSame(sb, sb.insert(0, -1));
1469        assertEquals("-10000", sb.toString());
1470        assertEquals(6, sb.length());
1471
1472        sb = new StringBuilder(fixture);
1473        assertSame(sb, sb.insert(0, 0));
1474        assertEquals("00000", sb.toString());
1475        assertEquals(5, sb.length());
1476
1477        sb = new StringBuilder(fixture);
1478        assertSame(sb, sb.insert(2, 1));
1479        assertEquals("00100", sb.toString());
1480        assertEquals(5, sb.length());
1481
1482        sb = new StringBuilder(fixture);
1483        assertSame(sb, sb.insert(4, 2));
1484        assertEquals("00002", sb.toString());
1485        assertEquals(5, sb.length());
1486
1487        try {
1488            sb = new StringBuilder(fixture);
1489            sb.insert(-1, 1);
1490            fail("no IOOBE, negative index");
1491        } catch (IndexOutOfBoundsException e) {
1492            // Expected
1493        }
1494
1495        try {
1496            sb = new StringBuilder(fixture);
1497            sb.insert(5, 1);
1498            fail("no IOOBE, index too large index");
1499        } catch (IndexOutOfBoundsException e) {
1500            // Expected
1501        }
1502    }
1503
1504    /**
1505     * @tests java.lang.StringBuilder.insert(int, long)
1506     */
1507    @TestTargetNew(
1508        level = TestLevel.COMPLETE,
1509        notes = "",
1510        method = "insert",
1511        args = {int.class, long.class}
1512    )
1513    public void test_insertIJ() {
1514        final String fixture = "0000";
1515        StringBuilder sb = new StringBuilder(fixture);
1516        assertSame(sb, sb.insert(0, -1L));
1517        assertEquals("-10000", sb.toString());
1518        assertEquals(6, sb.length());
1519
1520        sb = new StringBuilder(fixture);
1521        assertSame(sb, sb.insert(0, 0L));
1522        assertEquals("00000", sb.toString());
1523        assertEquals(5, sb.length());
1524
1525        sb = new StringBuilder(fixture);
1526        assertSame(sb, sb.insert(2, 1L));
1527        assertEquals("00100", sb.toString());
1528        assertEquals(5, sb.length());
1529
1530        sb = new StringBuilder(fixture);
1531        assertSame(sb, sb.insert(4, 2L));
1532        assertEquals("00002", sb.toString());
1533        assertEquals(5, sb.length());
1534
1535        try {
1536            sb = new StringBuilder(fixture);
1537            sb.insert(-1, 1L);
1538            fail("no IOOBE, negative index");
1539        } catch (IndexOutOfBoundsException e) {
1540            // Expected
1541        }
1542
1543        try {
1544            sb = new StringBuilder(fixture);
1545            sb.insert(5, 1L);
1546            fail("no IOOBE, index too large index");
1547        } catch (IndexOutOfBoundsException e) {
1548            // Expected
1549        }
1550    }
1551
1552    /**
1553     * @tests java.lang.StringBuilder.insert(int, Object)
1554     */
1555    @TestTargetNew(
1556        level = TestLevel.COMPLETE,
1557        notes = "",
1558        method = "insert",
1559        args = {int.class, java.lang.Object.class}
1560    )
1561    public void test_insertILjava_lang_Object() {
1562        final String fixture = "0000";
1563        StringBuilder sb = new StringBuilder(fixture);
1564        assertSame(sb, sb.insert(0, Fixture.INSTANCE));
1565        assertEquals("fixture0000", sb.toString());
1566        assertEquals(11, sb.length());
1567
1568        sb = new StringBuilder(fixture);
1569        assertSame(sb, sb.insert(2, Fixture.INSTANCE));
1570        assertEquals("00fixture00", sb.toString());
1571        assertEquals(11, sb.length());
1572
1573        sb = new StringBuilder(fixture);
1574        assertSame(sb, sb.insert(4, Fixture.INSTANCE));
1575        assertEquals("0000fixture", sb.toString());
1576        assertEquals(11, sb.length());
1577
1578        sb = new StringBuilder(fixture);
1579        assertSame(sb, sb.insert(4, (Object) null));
1580        assertEquals("0000null", sb.toString());
1581        assertEquals(8, sb.length());
1582
1583        try {
1584            sb = new StringBuilder(fixture);
1585            sb.insert(-1, Fixture.INSTANCE);
1586            fail("no IOOBE, negative index");
1587        } catch (IndexOutOfBoundsException e) {
1588            // Expected
1589        }
1590
1591        try {
1592            sb = new StringBuilder(fixture);
1593            sb.insert(5, Fixture.INSTANCE);
1594            fail("no IOOBE, index too large index");
1595        } catch (IndexOutOfBoundsException e) {
1596            // Expected
1597        }
1598    }
1599
1600    /**
1601     * @tests java.lang.StringBuilder.insert(int, String)
1602     */
1603    @TestTargetNew(
1604        level = TestLevel.COMPLETE,
1605        notes = "",
1606        method = "insert",
1607        args = {int.class, java.lang.String.class}
1608    )
1609    public void test_insertILjava_lang_String() {
1610        final String fixture = "0000";
1611        StringBuilder sb = new StringBuilder(fixture);
1612        assertSame(sb, sb.insert(0, "fixture"));
1613        assertEquals("fixture0000", sb.toString());
1614        assertEquals(11, sb.length());
1615
1616        sb = new StringBuilder(fixture);
1617        assertSame(sb, sb.insert(2, "fixture"));
1618        assertEquals("00fixture00", sb.toString());
1619        assertEquals(11, sb.length());
1620
1621        sb = new StringBuilder(fixture);
1622        assertSame(sb, sb.insert(4, "fixture"));
1623        assertEquals("0000fixture", sb.toString());
1624        assertEquals(11, sb.length());
1625
1626        sb = new StringBuilder(fixture);
1627        assertSame(sb, sb.insert(4, (Object) null));
1628        assertEquals("0000null", sb.toString());
1629        assertEquals(8, sb.length());
1630
1631        try {
1632            sb = new StringBuilder(fixture);
1633            sb.insert(-1, "fixture");
1634            fail("no IOOBE, negative index");
1635        } catch (IndexOutOfBoundsException e) {
1636            // Expected
1637        }
1638
1639        try {
1640            sb = new StringBuilder(fixture);
1641            sb.insert(5, "fixture");
1642            fail("no IOOBE, index too large index");
1643        } catch (IndexOutOfBoundsException e) {
1644            // Expected
1645        }
1646    }
1647
1648    /**
1649     * @tests java.lang.StringBuilder.lastIndexOf(String)
1650     */
1651    @TestTargetNew(
1652        level = TestLevel.COMPLETE,
1653        notes = "",
1654        method = "lastIndexOf",
1655        args = {java.lang.String.class}
1656    )
1657    public void test_lastIndexOfLjava_lang_String() {
1658        final String fixture = "0123456789";
1659        StringBuilder sb = new StringBuilder(fixture);
1660        assertEquals(0, sb.lastIndexOf("0"));
1661        assertEquals(0, sb.lastIndexOf("012"));
1662        assertEquals(-1, sb.lastIndexOf("02"));
1663        assertEquals(8, sb.lastIndexOf("89"));
1664
1665        try {
1666            sb.lastIndexOf(null);
1667            fail("no NPE");
1668        } catch (NullPointerException e) {
1669            // Expected
1670        }
1671    }
1672
1673    /**
1674     * @tests java.lang.StringBuilder.lastIndexOf(String, int)
1675     */
1676    @TestTargetNew(
1677        level = TestLevel.COMPLETE,
1678        notes = "",
1679        method = "lastIndexOf",
1680        args = {java.lang.String.class, int.class}
1681    )
1682    public void test_lastIndexOfLjava_lang_StringI() {
1683        final String fixture = "0123456789";
1684        StringBuilder sb = new StringBuilder(fixture);
1685        assertEquals(0, sb.lastIndexOf("0"));
1686        assertEquals(0, sb.lastIndexOf("012"));
1687        assertEquals(-1, sb.lastIndexOf("02"));
1688        assertEquals(8, sb.lastIndexOf("89"));
1689
1690        assertEquals(0, sb.lastIndexOf("0"), 0);
1691        assertEquals(0, sb.lastIndexOf("012"), 0);
1692        assertEquals(-1, sb.lastIndexOf("02"), 0);
1693        assertEquals(8, sb.lastIndexOf("89"), 0);
1694
1695        assertEquals(-1, sb.lastIndexOf("0"), 5);
1696        assertEquals(-1, sb.lastIndexOf("012"), 5);
1697        assertEquals(-1, sb.lastIndexOf("02"), 0);
1698        assertEquals(8, sb.lastIndexOf("89"), 5);
1699
1700        try {
1701            sb.lastIndexOf(null, 0);
1702            fail("no NPE");
1703        } catch (NullPointerException e) {
1704            // Expected
1705        }
1706    }
1707
1708    /**
1709     * @tests java.lang.StringBuilder.length()
1710     */
1711    @TestTargetNew(
1712        level = TestLevel.COMPLETE,
1713        notes = "",
1714        method = "length",
1715        args = {}
1716    )
1717    public void test_length() {
1718        StringBuilder sb = new StringBuilder();
1719        assertEquals(0, sb.length());
1720        sb.append("0000");
1721        assertEquals(4, sb.length());
1722    }
1723
1724    /**
1725     * @tests java.lang.StringBuilder.offsetByCodePoints(int, int)'
1726     */
1727    @TestTargetNew(
1728        level = TestLevel.COMPLETE,
1729        notes = "",
1730        method = "offsetByCodePoints",
1731        args = {int.class, int.class}
1732    )
1733    public void test_offsetByCodePointsII() {
1734        int result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(0, 2);
1735        assertEquals(3, result);
1736
1737        result = new StringBuilder("abcd").offsetByCodePoints(3, -1);
1738        assertEquals(2, result);
1739
1740        result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(0, 3);
1741        assertEquals(4, result);
1742
1743        result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(3, -1);
1744        assertEquals(1, result);
1745
1746        result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(3, 0);
1747        assertEquals(3, result);
1748
1749        result = new StringBuilder("\uD800\uDC00bc").offsetByCodePoints(3, 0);
1750        assertEquals(3, result);
1751
1752        result = new StringBuilder("a\uDC00bc").offsetByCodePoints(3, -1);
1753        assertEquals(2, result);
1754
1755        result = new StringBuilder("a\uD800bc").offsetByCodePoints(3, -1);
1756        assertEquals(2, result);
1757
1758        StringBuilder sb = new StringBuilder();
1759        sb.append("abc");
1760        try {
1761            sb.offsetByCodePoints(-1, 1);
1762            fail("No IOOBE for negative index.");
1763        } catch (IndexOutOfBoundsException e) {
1764
1765        }
1766
1767        try {
1768            sb.offsetByCodePoints(0, 4);
1769            fail("No IOOBE for offset that's too large.");
1770        } catch (IndexOutOfBoundsException e) {
1771
1772        }
1773
1774        try {
1775            sb.offsetByCodePoints(3, -4);
1776            fail("No IOOBE for offset that's too small.");
1777        } catch (IndexOutOfBoundsException e) {
1778
1779        }
1780
1781        try {
1782            sb.offsetByCodePoints(3, 1);
1783            fail("No IOOBE for index that's too large.");
1784        } catch (IndexOutOfBoundsException e) {
1785
1786        }
1787
1788        try {
1789            sb.offsetByCodePoints(4, -1);
1790            fail("No IOOBE for index that's too large.");
1791        } catch (IndexOutOfBoundsException e) {
1792
1793        }
1794    }
1795
1796    /**
1797     * @tests java.lang.StringBuilder.replace(int, int, String)'
1798     */
1799    @TestTargetNew(
1800        level = TestLevel.COMPLETE,
1801        notes = "",
1802        method = "replace",
1803        args = {int.class, int.class, java.lang.String.class}
1804    )
1805    public void test_replaceIILjava_lang_String() {
1806        final String fixture = "0000";
1807        StringBuilder sb = new StringBuilder(fixture);
1808        assertSame(sb, sb.replace(1, 3, "11"));
1809        assertEquals("0110", sb.toString());
1810        assertEquals(4, sb.length());
1811
1812        sb = new StringBuilder(fixture);
1813        assertSame(sb, sb.replace(1, 2, "11"));
1814        assertEquals("01100", sb.toString());
1815        assertEquals(5, sb.length());
1816
1817        sb = new StringBuilder(fixture);
1818        assertSame(sb, sb.replace(4, 5, "11"));
1819        assertEquals("000011", sb.toString());
1820        assertEquals(6, sb.length());
1821
1822        sb = new StringBuilder(fixture);
1823        assertSame(sb, sb.replace(4, 6, "11"));
1824        assertEquals("000011", sb.toString());
1825        assertEquals(6, sb.length());
1826
1827        // FIXME Undocumented NPE in Sun's JRE 5.0_5
1828        try {
1829            sb.replace(1, 2, null);
1830            fail("No NPE");
1831        } catch (NullPointerException e) {
1832            // Expected
1833        }
1834
1835        try {
1836            sb = new StringBuilder(fixture);
1837            sb.replace(-1, 2, "11");
1838            fail("No SIOOBE, negative start");
1839        } catch (StringIndexOutOfBoundsException e) {
1840            // Expected
1841        }
1842
1843        try {
1844            sb = new StringBuilder(fixture);
1845            sb.replace(5, 2, "11");
1846            fail("No SIOOBE, start > length");
1847        } catch (StringIndexOutOfBoundsException e) {
1848            // Expected
1849        }
1850
1851        try {
1852            sb = new StringBuilder(fixture);
1853            sb.replace(3, 2, "11");
1854            fail("No SIOOBE, start > end");
1855        } catch (StringIndexOutOfBoundsException e) {
1856            // Expected
1857        }
1858
1859        // Regression for HARMONY-348
1860        StringBuilder buffer = new StringBuilder("1234567");
1861        buffer.replace(2, 6, "XXX");
1862        assertEquals("12XXX7",buffer.toString());
1863    }
1864
1865    /**
1866     * @tests java.lang.StringBuilder.reverse()
1867     */
1868    @TestTargetNew(
1869        level = TestLevel.COMPLETE,
1870        notes = "",
1871        method = "reverse",
1872        args = {}
1873    )
1874    public void test_reverse() {
1875        final String fixture = "0123456789";
1876        StringBuilder sb = new StringBuilder(fixture);
1877        assertSame(sb, sb.reverse());
1878        assertEquals("9876543210", sb.toString());
1879
1880        sb = new StringBuilder("012345678");
1881        assertSame(sb, sb.reverse());
1882        assertEquals("876543210", sb.toString());
1883
1884        sb.setLength(1);
1885        assertSame(sb, sb.reverse());
1886        assertEquals("8", sb.toString());
1887
1888        sb.setLength(0);
1889        assertSame(sb, sb.reverse());
1890        assertEquals("", sb.toString());
1891    }
1892
1893    /**
1894     * @tests java.lang.StringBuilder.setCharAt(int, char)
1895     */
1896    @TestTargetNew(
1897        level = TestLevel.COMPLETE,
1898        notes = "",
1899        method = "setCharAt",
1900        args = {int.class, char.class}
1901    )
1902    public void test_setCharAtIC() {
1903        final String fixture = "0000";
1904        StringBuilder sb = new StringBuilder(fixture);
1905        sb.setCharAt(0, 'A');
1906        assertEquals("A000", sb.toString());
1907        sb.setCharAt(1, 'B');
1908        assertEquals("AB00", sb.toString());
1909        sb.setCharAt(2, 'C');
1910        assertEquals("ABC0", sb.toString());
1911        sb.setCharAt(3, 'D');
1912        assertEquals("ABCD", sb.toString());
1913
1914        try {
1915            sb.setCharAt(-1, 'A');
1916            fail("No IOOBE, negative index");
1917        } catch (IndexOutOfBoundsException e) {
1918            // Expected
1919        }
1920
1921        try {
1922            sb.setCharAt(4, 'A');
1923            fail("No IOOBE, index == length");
1924        } catch (IndexOutOfBoundsException e) {
1925            // Expected
1926        }
1927
1928        try {
1929            sb.setCharAt(5, 'A');
1930            fail("No IOOBE, index > length");
1931        } catch (IndexOutOfBoundsException e) {
1932            // Expected
1933        }
1934    }
1935
1936    /**
1937     * @tests java.lang.StringBuilder.setLength(int)'
1938     */
1939    @TestTargetNew(
1940        level = TestLevel.COMPLETE,
1941        notes = "",
1942        method = "setLength",
1943        args = {int.class}
1944    )
1945    public void test_setLengthI() {
1946        final String fixture = "0123456789";
1947        StringBuilder sb = new StringBuilder(fixture);
1948        sb.setLength(5);
1949        assertEquals(5, sb.length());
1950        assertEquals("01234", sb.toString());
1951        sb.setLength(6);
1952        assertEquals(6, sb.length());
1953        assertEquals("01234\0", sb.toString());
1954        sb.setLength(0);
1955        assertEquals(0, sb.length());
1956        assertEquals("", sb.toString());
1957
1958        try {
1959            sb.setLength(-1);
1960            fail("No IOOBE, negative length.");
1961        } catch (IndexOutOfBoundsException e) {
1962            // Expected
1963        }
1964    }
1965
1966    /**
1967     * @tests java.lang.StringBuilder.subSequence(int, int)
1968     */
1969    @TestTargetNew(
1970        level = TestLevel.PARTIAL,
1971        notes = "",
1972        method = "subSequence",
1973        args = {int.class, int.class}
1974    )
1975    public void test_subSequenceII() {
1976        final String fixture = "0123456789";
1977        StringBuilder sb = new StringBuilder(fixture);
1978        CharSequence ss = sb.subSequence(0, 5);
1979        assertEquals("01234", ss.toString());
1980
1981        ss = sb.subSequence(0, 0);
1982        assertEquals("", ss.toString());
1983
1984        try {
1985            sb.subSequence(-1, 1);
1986            fail("No IOOBE, negative start.");
1987        } catch (IndexOutOfBoundsException e) {
1988            // Expected
1989        }
1990
1991        try {
1992            sb.subSequence(0, -1);
1993            fail("No IOOBE, negative end.");
1994        } catch (IndexOutOfBoundsException e) {
1995            // Expected
1996        }
1997
1998        try {
1999            sb.subSequence(0, fixture.length() + 1);
2000            fail("No IOOBE, end > length.");
2001        } catch (IndexOutOfBoundsException e) {
2002            // Expected
2003        }
2004
2005        try {
2006            sb.subSequence(3, 2);
2007            fail("No IOOBE, start > end.");
2008        } catch (IndexOutOfBoundsException e) {
2009            // Expected
2010        }
2011    }
2012
2013    /**
2014     * @tests java.lang.StringBuilder.substring(int)
2015     */
2016    @TestTargetNew(
2017        level = TestLevel.COMPLETE,
2018        notes = "",
2019        method = "substring",
2020        args = {int.class}
2021    )
2022    public void test_substringI() {
2023        final String fixture = "0123456789";
2024        StringBuilder sb = new StringBuilder(fixture);
2025        String ss = sb.substring(0);
2026        assertEquals(fixture, ss);
2027
2028        ss = sb.substring(10);
2029        assertEquals("", ss);
2030
2031        try {
2032            sb.substring(-1);
2033            fail("No SIOOBE, negative start.");
2034        } catch (StringIndexOutOfBoundsException e) {
2035            // Expected
2036        }
2037
2038        try {
2039            sb.substring(0, -1);
2040            fail("No SIOOBE, negative end.");
2041        } catch (StringIndexOutOfBoundsException e) {
2042            // Expected
2043        }
2044
2045        try {
2046            sb.substring(fixture.length() + 1);
2047            fail("No SIOOBE, start > length.");
2048        } catch (StringIndexOutOfBoundsException e) {
2049            // Expected
2050        }
2051    }
2052
2053    /**
2054     * @tests java.lang.StringBuilder.substring(int, int)
2055     */
2056    @TestTargetNew(
2057        level = TestLevel.COMPLETE,
2058        notes = "",
2059        method = "substring",
2060        args = {int.class, int.class}
2061    )
2062    public void test_substringII() {
2063        final String fixture = "0123456789";
2064        StringBuilder sb = new StringBuilder(fixture);
2065        String ss = sb.substring(0, 5);
2066        assertEquals("01234", ss);
2067
2068        ss = sb.substring(0, 0);
2069        assertEquals("", ss);
2070
2071        try {
2072            sb.substring(-1, 1);
2073            fail("No SIOOBE, negative start.");
2074        } catch (StringIndexOutOfBoundsException e) {
2075            // Expected
2076        }
2077
2078        try {
2079            sb.substring(0, -1);
2080            fail("No SIOOBE, negative end.");
2081        } catch (StringIndexOutOfBoundsException e) {
2082            // Expected
2083        }
2084
2085        try {
2086            sb.substring(0, fixture.length() + 1);
2087            fail("No SIOOBE, end > length.");
2088        } catch (StringIndexOutOfBoundsException e) {
2089            // Expected
2090        }
2091
2092        try {
2093            sb.substring(3, 2);
2094            fail("No SIOOBE, start > end.");
2095        } catch (StringIndexOutOfBoundsException e) {
2096            // Expected
2097        }
2098    }
2099
2100    /**
2101     * @tests java.lang.StringBuilder.toString()'
2102     */
2103    @TestTargetNew(
2104        level = TestLevel.COMPLETE,
2105        notes = "",
2106        method = "toString",
2107        args = {}
2108    )
2109    public void test_toString() {
2110        final String fixture = "0123456789";
2111        StringBuilder sb = new StringBuilder(fixture);
2112        assertEquals(fixture, sb.toString());
2113    }
2114
2115    /**
2116     * @tests java.lang.StringBuilder.trimToSize()'
2117     */
2118    @TestTargetNew(
2119        level = TestLevel.COMPLETE,
2120        notes = "",
2121        method = "trimToSize",
2122        args = {}
2123    )
2124    public void test_trimToSize() {
2125        final String fixture = "0123456789";
2126        StringBuilder sb = new StringBuilder(fixture);
2127        assertTrue(sb.capacity() > fixture.length());
2128        assertEquals(fixture.length(), sb.length());
2129        assertEquals(fixture, sb.toString());
2130        int prevCapacity = sb.capacity();
2131        sb.trimToSize();
2132        assertTrue(prevCapacity > sb.capacity());
2133        assertEquals(fixture.length(), sb.length());
2134        assertEquals(fixture, sb.toString());
2135    }
2136
2137    // comparator for StringBuilder objects
2138    private static final SerializableAssert STRING_BILDER_COMPARATOR = new SerializableAssert() {
2139        public void assertDeserialized(Serializable initial,
2140                Serializable deserialized) {
2141
2142            StringBuilder init = (StringBuilder) initial;
2143            StringBuilder desr = (StringBuilder) deserialized;
2144
2145            assertEquals("toString", init.toString(), desr.toString());
2146        }
2147    };
2148
2149    /**
2150     * @tests serialization/deserialization.
2151     */
2152    @TestTargetNew(
2153        level = TestLevel.COMPLETE,
2154        notes = "Verifies serialization/deserialization.",
2155        method = "!SerializationSelf",
2156        args = {}
2157    )
2158    public void testSerializationSelf() throws Exception {
2159
2160        SerializationTest.verifySelf(new StringBuilder("0123456789"),
2161                STRING_BILDER_COMPARATOR);
2162    }
2163
2164    /**
2165     * @tests serialization/deserialization compatibility with RI.
2166     */
2167    @TestTargetNew(
2168        level = TestLevel.COMPLETE,
2169        notes = "Verifies serialization/deserialization compatibility.",
2170        method = "!SerializationGolden",
2171        args = {}
2172    )
2173    public void testSerializationCompatibility() throws Exception {
2174
2175        SerializationTest.verifyGolden(this, new StringBuilder("0123456789"),
2176                STRING_BILDER_COMPARATOR);
2177    }
2178
2179    private static final class Fixture {
2180        static final Fixture INSTANCE = new Fixture();
2181
2182        private Fixture() {
2183            super();
2184        }
2185
2186        @Override
2187        public String toString() {
2188            return "fixture";
2189        }
2190    }
2191}
2192