Permalink
Browse files

Added round-trip tests for JDOMStreamReader.java

Signed-off-by: gburgett <gordon.burgett@gmail.com>
  • Loading branch information...
1 parent 4521c3b commit 660ae1170a6d0fcc6a0c72600dc2fce886093786 @gburgett committed Jan 7, 2013
@@ -69,6 +69,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.jdom2.Element;
import org.jdom2.EntityRef;
import org.jdom2.Namespace;
+import org.jdom2.Parent;
import org.jdom2.ProcessingInstruction;
import org.jdom2.Text;
@@ -115,25 +116,19 @@ public Object getProperty(String name) throws IllegalArgumentException {
public int next() throws XMLStreamException {
switch(state){
case RS_START_DOCUMENT:
- state = ReaderState.RS_START_ROOT_ELEMENT;
- return currentEvt = START_DOCUMENT;
-
- case RS_START_ROOT_ELEMENT:
- state = ReaderState.RS_WALKING_TREE;
- this.rootIterator = new DomWalkingContentIterator(root);
- return currentEvt = START_ELEMENT;
+ if(this.rootIterator == null){
+ state = ReaderState.RS_WALKING_TREE;
+ this.rootIterator = new DomWalkingContentIterator(this.document);
+ return currentEvt = START_DOCUMENT;
+ }
case RS_WALKING_TREE:
if(this.rootIterator.hasNext()){
return currentEvt = this.rootIterator.next();
}
- state = ReaderState.RS_END_ROOT_ELEMENT;
- return currentEvt = END_ELEMENT;
-
- case RS_END_ROOT_ELEMENT:
- state = ReaderState.RS_END_DOCUMENT;
- return currentEvt = END_DOCUMENT;
-
+ state = ReaderState.RS_END_DOCUMENT;
+ return currentEvt = END_DOCUMENT;
+
default:
throw new IllegalStateException("Reader does not have next");
}
@@ -690,9 +685,9 @@ public Content getCurrentContent(){
return ret;
}
- private Element toWalk;
+ private Parent toWalk;
- public DomWalkingContentIterator(Element toWalk){
+ public DomWalkingContentIterator(Parent toWalk){
this.toWalk = toWalk;
}
@@ -782,9 +777,7 @@ private int getEventType(Content c){
*/
private enum ReaderState{
RS_START_DOCUMENT,
- RS_START_ROOT_ELEMENT,
RS_WALKING_TREE,
- RS_END_ROOT_ELEMENT,
RS_END_DOCUMENT,
RS_CLOSED
}
@@ -0,0 +1,22 @@
+package org.jdom2.test.cases.output;
+
+import org.jdom2.Document;
+import org.jdom2.JDOMException;
+import org.jdom2.input.StAXStreamBuilder;
+import org.jdom2.jaxb.JDOMStreamReader;
+
+@SuppressWarnings("javadoc")
+public class TestStAXWriterReader extends AbstractTestRoundTrip {
+
+ @Override
+ Document roundTrip(final Document doc) {
+ final JDOMStreamReader sr = new JDOMStreamReader(doc);
+ final StAXStreamBuilder sb = new StAXStreamBuilder();
+ try {
+ return sb.build(sr);
+ } catch (JDOMException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+}

0 comments on commit 660ae11

Please sign in to comment.