Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CloneBase to simplify clone() method calls which in turn cleans u…
…p the coverage reports. Fix some JavaDoc issues and lots of small coverage improvements
- Loading branch information
Showing
19 changed files
with
377 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jdom2; | ||
|
||
/** | ||
* This simple class just tidies up any cloneable classes. | ||
* This method deals with any CloneNotSupported exceptions. | ||
* THis class is package private only. | ||
* @author Rolf Lear | ||
* | ||
*/ | ||
class CloneBase implements Cloneable { | ||
|
||
/** | ||
* This convenience method simply deals with the irritating | ||
* CloneNotSupportedException, and wraps it in IllegalStateException. | ||
* This should never, ever, ever happen. But, it is a pain to deal with | ||
* ugly clone code in some classes. | ||
* Subclasses of this should still call super.clone() in their clone method. | ||
*/ | ||
@Override | ||
protected Object clone() { | ||
try { | ||
return super.clone(); | ||
} catch (CloneNotSupportedException e) { | ||
throw new IllegalStateException(String.format( | ||
"Unable to clone class %s which should always support it.", | ||
this.getClass().getName()), | ||
e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jdom2; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
@SuppressWarnings("javadoc") | ||
public class TestJDOMRuntimeExceptn { | ||
|
||
@Test | ||
public void testJDOMRuntimeException() { | ||
assertTrue (null != new JDOMRuntimeException().getMessage()); | ||
assertEquals (null, new JDOMRuntimeException().getCause()); | ||
|
||
} | ||
|
||
@Test | ||
public void testJDOMRuntimeExceptionString() { | ||
assertEquals ("reason", new JDOMRuntimeException("reason").getMessage()); | ||
|
||
} | ||
|
||
@Test | ||
public void testJDOMRuntimeExceptionStringExn() { | ||
Throwable t = new Throwable(); | ||
Exception e = new JDOMRuntimeException("reason", t); | ||
assertTrue (t == e.getCause()); | ||
assertEquals("reason", e.getMessage()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/src/java/org/jdom2/test/cases/TestSlimJDOMFactoryNoText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jdom2.test.cases; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
|
||
import org.jdom2.JDOMFactory; | ||
import org.jdom2.SlimJDOMFactory; | ||
import org.jdom2.Text; | ||
|
||
@SuppressWarnings("javadoc") | ||
public class TestSlimJDOMFactoryNoText extends AbstractTestJDOMFactory { | ||
|
||
@Override | ||
protected JDOMFactory buildFactory() { | ||
return new SlimJDOMFactory(false); | ||
} | ||
|
||
@Test | ||
public void testCaching() { | ||
SlimJDOMFactory fac = new SlimJDOMFactory(false); | ||
Text ta = fac.text("hi"); | ||
String hi = ta.getText(); | ||
// we expect the StringBin to compact a string value... should no longer | ||
// be the intern value. | ||
assertTrue("hi" == hi); | ||
assertTrue("hi" == hi.intern()); | ||
|
||
Text tb = fac.text("hi"); | ||
assertTrue("hi" == tb.getText()); | ||
assertTrue(hi == tb.getText()); | ||
|
||
fac.clearCache(); | ||
|
||
Text tc = fac.text("hi"); | ||
assertTrue("hi" == tc.getText()); | ||
assertTrue(hi == tc.getText()); | ||
|
||
assertTrue(hi.equals(tc.getText())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.