ConditionDescriptorNodesParser { public List<ConditionDescriptor> parseNodesOfElement(final Document document, final Element element) { List<ConditionDescriptor> result = new ArrayList<>(); NodeList conditionDescriptorNodes = element.getElementsByTagName(ConditionDescriptor.TAG_NAME); for (int i = 0; i < conditionDescriptorNodes.getLength(); i++) { ConditionDescriptor conditionDescriptor = conditionDescriptorParser.parseNode(conditionDescriptorNodes.item(i), document); result.add(conditionDescriptor); } return result; }  List<ConditionDescriptor> parseNodesOfElement(final Document document, final Element element);  }
@Test public void testParseNodesOfElementShouldReturnEmptyListWhenNoConditionDescriptorsExist() { given(element.getElementsByTagName(ConditionDescriptor.TAG_NAME)).willReturn(nodeList); given(nodeList.getLength()).willReturn(0); List<ConditionDescriptor> result = underTest.parseNodesOfElement(document, element); assertTrue(result.isEmpty()); }
@Test public void testParseNodesOfElement() { List<ConditionDescriptor> expected = new ArrayList<>(); expected.add(conditionDescriptor); expected.add(conditionDescriptor); given(element.getElementsByTagName(ConditionDescriptor.TAG_NAME)).willReturn(nodeList); given(nodeList.getLength()).willReturn(2); given(nodeList.item(0)).willReturn(conditionDescriptorElement); given(nodeList.item(1)).willReturn(conditionDescriptorElement); given(conditionDescriptorParser.parseNode(conditionDescriptorElement, document)).willReturn(conditionDescriptor); List<ConditionDescriptor> result = underTest.parseNodesOfElement(document, element); assertEquals(expected, result); }