-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
canabrook
authored and
canabrook
committed
Oct 18, 2022
1 parent
65fb3e2
commit 4bcb91f
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/com/berryworks/edireader/util/dom/ChildElementsTest.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,58 @@ | ||
package com.berryworks.edireader.util.dom; | ||
|
||
import com.berryworks.edireader.benchmark.EDITestData; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import java.util.ListIterator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ChildElementsTest { | ||
|
||
private Element transactionElement; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Document dom = DocumentUtil.getInstance().buildDocumentFromEdi(EDITestData.getAnsiInputSource()); | ||
transactionElement = DocumentUtil.position(dom.getDocumentElement(), new String[]{"interchange", "group", "transaction"}); | ||
} | ||
|
||
@Test | ||
public void canIterateOverAllChildren() { | ||
ChildElements children = new ChildElements(transactionElement); | ||
ListIterator<Element> iterator = children.listIterator(); | ||
int count = 0; | ||
while (iterator.hasNext()) { | ||
Element childElement = iterator.next(); | ||
count++; | ||
} | ||
assertEquals(9, count); | ||
} | ||
|
||
@Test | ||
public void canIterateOverAllChildrenHavingTag() { | ||
// Count the <segment> children | ||
ChildElements children = new ChildElements(transactionElement, "segment"); | ||
ListIterator<Element> iterator = children.listIterator(); | ||
int count = 0; | ||
while (iterator.hasNext()) { | ||
Element childElement = iterator.next(); | ||
assertEquals("segment", childElement.getTagName()); | ||
count++; | ||
} | ||
assertEquals(1, count); | ||
|
||
// Count the <loop> children | ||
iterator = new ChildElements(transactionElement, "loop").listIterator(); | ||
count = 0; | ||
while (iterator.hasNext()) { | ||
Element childElement = iterator.next(); | ||
assertEquals("loop", childElement.getTagName()); | ||
count++; | ||
} | ||
assertEquals(8, count); | ||
} | ||
} |