DialogDescriptorReferenceParser { public List<DialogDescriptor> parse(final Element sequenceElement, final Map<String, DialogDescriptor> nameToDialogDescriptor) { List<DialogDescriptor> result = new ArrayList<>(); NodeList dialogDescriptorReferences = sequenceElement.getElementsByTagName(DIALOG_DESCRIPTOR_REFERENCE_TAG_NAME); for (int i = 0; i < dialogDescriptorReferences.getLength(); i++) { Element dialogDescriptorReferenceElement = (Element) dialogDescriptorReferences.item(i); String referencedName = dialogDescriptorReferenceElement.getAttribute("ref"); DialogDescriptor dialogDescriptor = nameToDialogDescriptor.get(referencedName); if (dialogDescriptor != null) { result.add(dialogDescriptor); } } return result; }  List<DialogDescriptor> parse(final Element sequenceElement, final Map<String, DialogDescriptor> nameToDialogDescriptor);  }
@Test public void testParse() { dialogDescriptorOne = new DialogDescriptor(null, null, null); dialogDescriptorTwo = new DialogDescriptor(null, null, null); List<DialogDescriptor> expected = new ArrayList<>(); expected.add(dialogDescriptorOne); nameToDialogDescriptor.put("one", dialogDescriptorOne); nameToDialogDescriptor.put("two", dialogDescriptorTwo); given(sequenceElement.getElementsByTagName(DIALOG_DESCRIPTOR_REFERENCE_TAG_NAME)).willReturn(nodeList); given(nodeList.getLength()).willReturn(1); given(nodeList.item(0)).willReturn(dialogDescriptorReferenceElement); given(dialogDescriptorReferenceElement.getAttribute(DIALOG_DESCRIPTOR_REFERENCE_NAME_ATTRIBUTE)).willReturn("one"); List<DialogDescriptor> result = underTest.parse(sequenceElement, nameToDialogDescriptor); assertEquals(expected, result); }