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:
Gary D. Gregory 2005-08-28 20:23:22 +00:00
parent fe4956d5ab
commit b26d9c7877
2 changed files with 32 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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