clone method is now full covered in unit tests.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@263912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe4956d5ab
commit
b26d9c7877
|
@ -1048,22 +1048,32 @@ public class StrTokenizer implements ListIterator, Cloneable {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Creates a new instance of this Tokenizer.
|
||||
* The new instance is reset so that it will be at the start of the token list.
|
||||
* Creates a new instance of this Tokenizer. The new instance is reset so that it will be at the start of the token
|
||||
* list. If a {@link CloneNotSupportedException} is caught, return <code>null</code>.
|
||||
*
|
||||
* @return a new instance of this Tokenizer which has been reset.
|
||||
*/
|
||||
public Object clone() {
|
||||
try {
|
||||
StrTokenizer cloned = (StrTokenizer) super.clone();
|
||||
if (cloned.chars != null) {
|
||||
cloned.chars = (char[]) cloned.chars.clone();
|
||||
}
|
||||
cloned.reset();
|
||||
return cloned;
|
||||
|
||||
return cloneReset();
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this Tokenizer. The new instance is reset so that it will be at the start of the token
|
||||
* list.
|
||||
*
|
||||
* @return a new instance of this Tokenizer which has been reset.
|
||||
*/
|
||||
protected Object cloneReset() throws CloneNotSupportedException {
|
||||
StrTokenizer cloned = (StrTokenizer) super.clone();
|
||||
if (cloned.chars != null) {
|
||||
cloned.chars = (char[]) cloned.chars.clone();
|
||||
}
|
||||
cloned.reset();
|
||||
return cloned;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -542,6 +542,19 @@ public class StrTokenizerTest extends TestCase {
|
|||
assertEquals(tok, tok.setIgnoreEmptyTokens(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the {@link StrTokenizer#clone()} clone method catches {@link CloneNotSupportedException} and returns
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public void testCloneNotSupportedException() {
|
||||
Object notCloned = (new StrTokenizer() {
|
||||
public Object cloneReset() throws CloneNotSupportedException {
|
||||
throw new CloneNotSupportedException("test");
|
||||
}
|
||||
}).clone();
|
||||
assertNull(notCloned);
|
||||
}
|
||||
|
||||
public void testCloneNull() {
|
||||
StrTokenizer tokenizer = new StrTokenizer((char[]) null);
|
||||
// Start sanity check
|
||||
|
|
Loading…
Reference in New Issue