Author: ggregory Date: Sun Aug 28 13:23:22 2005 New Revision: 263912 URL: http://svn.apache.org/viewcvs?rev=263912&view=rev Log: clone method is now full covered in unit tests.
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=263912&r1=263911&r2=263912&view=diff ============================================================================== --- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java (original) +++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java Sun Aug 28 13:23:22 2005 @@ -1048,22 +1048,32 @@ //----------------------------------------------------------------------- /** - * 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 [EMAIL PROTECTED] 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; } } Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java?rev=263912&r1=263911&r2=263912&view=diff ============================================================================== --- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java (original) +++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java Sun Aug 28 13:23:22 2005 @@ -542,6 +542,19 @@ assertEquals(tok, tok.setIgnoreEmptyTokens(false)); } + /** + * Tests that the [EMAIL PROTECTED] StrTokenizer#clone()} clone method catches [EMAIL PROTECTED] 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]