Fix clone() and add a unit test.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@234360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9a6a8b6862
commit
0d0b5165e9
|
@ -1056,7 +1056,7 @@ public class StrTokenizer implements ListIterator, Cloneable {
|
|||
try {
|
||||
StrTokenizer cloned = (StrTokenizer) super.clone();
|
||||
if (cloned.chars != null) {
|
||||
cloned.chars = cloned.chars;
|
||||
cloned.chars = (char[]) cloned.chars.clone();
|
||||
}
|
||||
cloned.reset();
|
||||
return cloned;
|
||||
|
|
|
@ -542,7 +542,35 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(tok, tok.setIgnoreEmptyTokens(false));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testCloneNull() {
|
||||
StrTokenizer tokenizer = new StrTokenizer((char[]) null);
|
||||
// Start sanity check
|
||||
assertEquals(null, tokenizer.nextToken());
|
||||
tokenizer.reset();
|
||||
assertEquals(null, tokenizer.nextToken());
|
||||
// End sanity check
|
||||
StrTokenizer clonedTokenizer = (StrTokenizer) tokenizer.clone();
|
||||
tokenizer.reset();
|
||||
assertEquals(null, tokenizer.nextToken());
|
||||
assertEquals(null, clonedTokenizer.nextToken());
|
||||
}
|
||||
|
||||
public void testCloneReset() {
|
||||
char[] input = new char[]{'a'};
|
||||
StrTokenizer tokenizer = new StrTokenizer(input);
|
||||
// Start sanity check
|
||||
assertEquals("a", tokenizer.nextToken());
|
||||
tokenizer.reset();
|
||||
assertEquals("a", tokenizer.nextToken());
|
||||
// End sanity check
|
||||
StrTokenizer clonedTokenizer = (StrTokenizer) tokenizer.clone();
|
||||
input[0] = 'b';
|
||||
tokenizer.reset();
|
||||
assertEquals("b", tokenizer.nextToken());
|
||||
assertEquals("a", clonedTokenizer.nextToken());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
public void testConstructor_String() {
|
||||
StrTokenizer tok = new StrTokenizer("a b");
|
||||
assertEquals("a", tok.next());
|
||||
|
|
Loading…
Reference in New Issue