SolrDocumentServiceImpl implements SolrDocumentService { @Override public SolrDocument getDocument(String docId) { final SolrQuery query = queryFactory.createDocumentQuery(docId); final SolrDocumentList result = searchResultsDao.getDocuments(query); if (result.size() < 1) { return null; } else { logger.debug("Document with docId {} retrieved:", result); return result.get(0); } } SolrDocumentServiceImpl(SearchResultsDao searchResultsDao, SolrDocumentQueryFactory queryFactory); @Override SolrDocument getDocument(String docId); @Override SolrDocumentExpansionPair getDocumentWithExpansion(String docId, String collapseField, QueryFacetsSelection selection, int expansionFirst, int expansionCount); @Override List<SolrDocument> getDocuments(QueryFacetsSelection selection, int first, int count); @Override SolrDocumentExpansionList getDocumentsWithExpansion(QueryFacetsSelection selection, int first, int count, String collapseField); @Override long getResultCount(QueryFacetsSelection selection); @Override long getTotalDocumentCount(QueryFacetsSelection selection);  }
@Test public void testGetDocument() { final SolrQuery solrQuery = new SolrQuery("query"); final SolrDocument resultDocument = new SolrDocument(); resultDocument.setField("id", "documentId"); final SolrDocumentList resultList = new SolrDocumentList(); resultList.add(resultDocument); context.checking(new Expectations() { { oneOf(queryFactory).createDocumentQuery("documentId"); will(returnValue(solrQuery)); oneOf(dao).getDocuments(solrQuery); will(returnValue(resultList)); } }); final SolrDocument result = instance.getDocument("documentId"); assertEquals(resultDocument, result); assertEquals("documentId", result.getFieldValue("id")); }