### Question:
RsDocumentBuilder { public Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId) { Urlset capabilityList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { RsMd rsMd = new RsMd(Capability.CAPABILITYLIST.xmlValue); capabilityList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForWellKnownResourceSync())); DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); String descriptionUrl = rsUriHelper.uriForRsDocument(dataSetMetaData, DESCRIPTION_FILENAME); capabilityList.addLink(new RsLn(REL_DESCRIBED_BY, descriptionUrl) .withType(DESCRIPTION_TYPE)); String loc = rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.RESOURCELIST); UrlItem item = new UrlItem(loc) .withMetadata(new RsMd(Capability.RESOURCELIST.xmlValue)); capabilityList.addItem(item); String loc2 = rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CHANGELIST); UrlItem item2 = new UrlItem(loc2) .withMetadata(new RsMd(Capability.CHANGELIST.xmlValue)); capabilityList.addItem(item2); } return Optional.ofNullable(capabilityList); } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); Urlset getSourceDescription(@Nullable User user); Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getResourceList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId); Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<Stream<String>> getResourceData(@Nullable User user, String ownerId, String dataSetId); Optional<CachedFile> getCachedFile(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<File> getDataSetDescription(@Nullable User user, String ownerId, String dataSetId); static final String SOURCE_DESCRIPTION_PATH; }### Answer:
@Test public void capabilityList() throws Exception { when(dataSetRepository.getDataSet(null, "u1", "ds1")).thenReturn(Optional.of(dataSet)); Urlset capabilityList = rsDocumentBuilder.getCapabilityList(null, "u1", "ds1").get(); String xml = rsBuilder.toXml(capabilityList, true); rsBuilder.setXmlString(xml).build(); Urlset cl = rsBuilder.getUrlset().get(); assertThat(cl.getCapability().get(), is(Capability.CAPABILITYLIST)); assertThat(cl.getLink("up").get().getHref(), is("http: assertThat(cl.getLink("describedby").get().getHref(), is("http: assertThat(cl.getLink("describedby").get().getType().get(), is("application/rdf+xml")); assertThat(cl.getItemList().size(), is(2)); assertThat(cl.getItemList().get(0).getLoc(), is("http: assertThat(cl.getItemList().get(0).getMetadata().get().getCapability().get(), is(Capability.RESOURCELIST.xmlValue)); assertThat(cl.getItemList().get(1).getLoc(), is("http: assertThat(cl.getItemList().get(1).getMetadata().get().getCapability().get(), is(Capability.CHANGELIST.xmlValue)); }