|
@@ -241,6 +241,30 @@ public class TestText extends TestCase {
|
|
|
Text.validateUTF8(utf8, 0, length);
|
|
|
}
|
|
|
|
|
|
+ public void testClear() throws Exception {
|
|
|
+ // Test lengths on an empty text object
|
|
|
+ Text text = new Text();
|
|
|
+ assertEquals(
|
|
|
+ "Actual string on an empty text object must be an empty string",
|
|
|
+ "", text.toString());
|
|
|
+ assertEquals("Underlying byte array length must be zero",
|
|
|
+ 0, text.getBytes().length);
|
|
|
+ assertEquals("String's length must be zero",
|
|
|
+ 0, text.getLength());
|
|
|
+
|
|
|
+ // Test if clear works as intended
|
|
|
+ text = new Text("abcd\u20acbdcd\u20ac");
|
|
|
+ int len = text.getLength();
|
|
|
+ text.clear();
|
|
|
+ assertEquals("String must be empty after clear()",
|
|
|
+ "", text.toString());
|
|
|
+ assertTrue(
|
|
|
+ "Length of the byte array must not decrease after clear()",
|
|
|
+ text.getBytes().length >= len);
|
|
|
+ assertEquals("Length of the string must be reset to 0 after clear()",
|
|
|
+ 0, text.getLength());
|
|
|
+ }
|
|
|
+
|
|
|
public void testTextText() throws CharacterCodingException {
|
|
|
Text a=new Text("abc");
|
|
|
Text b=new Text("a");
|