SequenceDescriptorParser { public List<SequenceDescriptor> parse(final Document document, final Element root, final List<DialogDescriptor> dialogDescriptors) { NodeList sequenceDescriptorNodes = root.getElementsByTagName(SequenceDescriptor.TAG_NAME); List<SequenceDescriptor> sequenceDescriptors = new ArrayList<>(); for (int i = 0; i < sequenceDescriptorNodes.getLength(); i++) { Element sequenceElement = (Element) sequenceDescriptorNodes.item(i); SequenceDescriptor sequenceDescriptor = sequenceDescriptorFactory.create(document, sequenceElement, dialogDescriptors); sequenceDescriptors.add(sequenceDescriptor); } return sequenceDescriptors; }  List<SequenceDescriptor> parse(final Document document, final Element root, final List<DialogDescriptor> dialogDescriptors);  }
@Test public void testParseShouldReturnEmptyListWhenNoSequenceDescriptorExists() { given(rootElement.getElementsByTagName(SEQUENCE_DESCRIPTOR_TAG_NAME)).willReturn(nodeList); given(nodeList.getLength()).willReturn(0); List<SequenceDescriptor> result = underTest.parse(document, rootElement, dialogDescriptors); assertTrue(result.isEmpty()); }
@Test public void testParse() { List<SequenceDescriptor> expected = new ArrayList<>(); expected.add(sequenceDescriptor); expected.add(sequenceDescriptor); dialogDescriptors = new ArrayList<>(); given(rootElement.getElementsByTagName(SEQUENCE_DESCRIPTOR_TAG_NAME)).willReturn(nodeList); given(nodeList.getLength()).willReturn(2); given(nodeList.item(0)).willReturn(sequenceElement); given(nodeList.item(1)).willReturn(sequenceElement); given(sequenceDescriptorFactory.create(document, sequenceElement, dialogDescriptors)).willReturn(sequenceDescriptor); List<SequenceDescriptor> result = underTest.parse(document, rootElement, dialogDescriptors); assertEquals(expected, result); }