### Question:
EntityServiceImpl implements EntityService { @Override public Model retrieveWorkItemsByURI(XURI xuri) { Model allItemsModel = ModelFactory.createDefaultModel(); Model workModel = repository.retrieveWorkAndLinkedResourcesByURI(xuri); QueryExecution queryExecution = QueryExecutionFactory.create(QueryFactory.create( "PREFIX deichman: <" + ontology() + "> " + "SELECT * " + "WHERE { ?publicationUri deichman:recordId ?biblioId }"), workModel); ResultSet publicationSet = queryExecution.execSelect(); while (publicationSet.hasNext()) { QuerySolution solution = publicationSet.next(); RDFNode publicationUri = solution.get("publicationUri"); String biblioId = solution.get("biblioId").asLiteral().getString(); Model itemsForBiblio = kohaAdapter.getBiblio(biblioId); SPARQLQueryBuilder sqb = new SPARQLQueryBuilder(); Query query = sqb.getItemsFromModelQuery(publicationUri.toString()); QueryExecution qexec = QueryExecutionFactory.create(query, itemsForBiblio); Model itemsModelWithBlankNodes = qexec.execConstruct(); allItemsModel.add(itemsModelWithBlankNodes); } return allItemsModel; } EntityServiceImpl(RDFRepository repository, KohaAdapter kohaAdapter); @Override Model retrieveById(XURI xuri); @Override Model retrieveCompleteResourceById(XURI xuri); @Override Model retrieveWorkWithLinkedResources(XURI xuri); @Override Model retrievePersonWithLinkedResources(XURI xuri); @Override Model retrieveCorporationWithLinkedResources(XURI xuri); @Override Model retrieveAuthorizedValuesFor(String type); @Override void updateWork(String work); @Override Model retrieveWorkItemsByURI(XURI xuri); @Override String create(EntityType type, Model inputModel); @Override void delete(Model model); @Override Model patch(XURI xuri, String ldPatchJson); @Override Model synchronizeKoha(XURI xuri); MarcRecord generateMarcRecordForPublication(XURI publication, Model work); @Override boolean resourceExists(XURI xuri); @Override Model retrieveWorksByCreator(XURI xuri); @Override void retrieveAllWorkUris(String type, Consumer<String> uriConsumer); @Override Optional<String> retrieveImportedResource(String id, String type); @Override List<String> retrieveWorkRecordIds(XURI xuri); @Override Map<String, Integer> getNumberOfRelationsForResource(XURI uri); @Override Model retrieveResourceByQuery(EntityType entityType, Map<String, String> queryParameters, Collection<String> projection); @Override Model describePublicationFromParsedCoreISBNQuery(String isbn); @Override Model retrieveEventWithLinkedResources(XURI eventUri); @Override Model retrieveSerialWithLinkedResources(XURI serialUri); @Override Set<String> retrieveResourcesConnectedTo(XURI xuri); StmtIterator statementsInModelAbout(final XURI xuri, final Model indexModel, final String... possibleNamePredicates); @Override List<RelationshipGroup> retrieveResourceRelationships(final XURI uri); @Override List<XURI> retrieveResourceRelationshipsUris(XURI uri); @Override List<ResourceSummary> retrieveInverseRelations(XURI xuri, String predicate, List<String> projections); @Override void deleteIncomingRelations(XURI xuri); @Override void mergeResource(XURI xuri, XURI replaceeUri); @Override RDFRepository getRepo(); static final Gson GSON; static final String HOLD_IS_FOUND; static final Integer THREE; }### Answer:
@Test public void test_retrieve_work_items_by_id() throws Exception { when(mockKohaAdapter.getBiblio("626460")).thenReturn(EntityServiceImplTest.modelForBiblio()); EntityService myService = new EntityServiceImpl(repositoryWithDataFrom("testdata.ttl"), mockKohaAdapter); Model m = myService.retrieveWorkItemsByURI(new XURI("http: Property p = createProperty("http: ResIterator ni = m.listSubjectsWithProperty(p); int i = 0; while (ni.hasNext()) { i++; ni.next(); } final int expectedNoOfItems = 2; assertEquals(expectedNoOfItems, i); }