### Question:
FoxmlDocumentHelpers { public static List<DatastreamVersion> listDatastreamVersions(Document foxml, String name) { Element dsEl = getDatastreamElByName(foxml, name); if (dsEl == null) { return null; } List<DatastreamVersion> result = new ArrayList<>(); for (Element dsvEl: dsEl.getChildren("datastreamVersion", FOXML_NS)) { String versionName = dsvEl.getAttributeValue("ID"); String mimeType = dsvEl.getAttributeValue("MIMETYPE"); String size = dsvEl.getAttributeValue("SIZE"); String created = dsvEl.getAttributeValue("CREATED"); Element digestEl = dsvEl.getChild("contentDigest", FOXML_NS); String md5 = digestEl == null ? null : digestEl.getAttributeValue("DIGEST"); String altIds = dsvEl.getAttributeValue("ALT_IDS"); DatastreamVersion dsVersion = new DatastreamVersion(md5, name, versionName, created, size, mimeType, altIds); Element bodyEl = dsvEl.getChild("xmlContent", FOXML_NS); if (bodyEl != null) { dsVersion.setBodyEl(bodyEl.getChildren().get(0)); } result.add(dsVersion); } result.sort((dsV1, dsV2) -> dsV1.getCreated().compareTo(dsV2.getCreated())); return result; } private  FoxmlDocumentHelpers(); static Set<String> listDatastreams(Document foxml); static Model getObjectModel(Document foxml); static Element getDatastreamElByName(Document foxml, String name); static String getFoxmlPid(Document foxml); static InputStream convertRelsExtToStream(Element el); static List<DatastreamVersion> listDatastreamVersions(Document foxml, String name); static final String RELS_EXT_DS; static final String MODS_DS; static final String FITS_DS; static final String DC_DS; static final String PREMIS_DS; static final String MANIFEST_DS; static final String ORIGINAL_DS; }### Answer:
@Test public void listDatastreamVersionsOutOfOrder() throws Exception { Document foxml = createSAXBuilder().build(getClass().getResource("/foxml/fileMultipleDataFile.xml")); List<DatastreamVersion> dsVersions = FoxmlDocumentHelpers.listDatastreamVersions(foxml, ORIGINAL_DS); assertEquals(3, dsVersions.size()); DatastreamVersion v0 = dsVersions.get(0); assertEquals("DATA_FILE.0", v0.getVersionName()); assertEquals("2011-10-13T17:56:37.993Z", v0.getCreated()); assertEquals("99fc2ca39feea757475df7caa4a8dbac", v0.getMd5()); assertEquals("text/plain", v0.getMimeType()); DatastreamVersion v2 = dsVersions.get(2); assertEquals("DATA_FILE.2", v2.getVersionName()); assertEquals("2011-12-05T15:00:54.408Z", v2.getCreated()); assertEquals("a4443ebd04da89c898a448a48f71e7b3", v2.getMd5()); assertEquals("application/pdf", v2.getMimeType()); }