public static DocumentList wrap(Iterator<ODocument> docs) { DocumentList list = new DocumentList(); while (docs.hasNext()) { ODocument next = docs.next(); list.add(DBUtil.documentToModel(next)); } return list; }
@Test public void shouldReturnCountOfProcessedDocuments() throws Exception { // given: DocumentTypes.addDocumentType("customType"); DocumentList documentList = new DocumentList(); documentList.add(emptyDocument()); documentList.add(emptyDocument()); // return empty DocumentList independent from DocumentType when(db.getUnrenderedContent(anyString())).thenReturn(emptyDocumentList); // return given DocumentList for DocumentType 'custom type' when(db.getUnrenderedContent("customType")).thenReturn(documentList); // when: int renderResponse = documentsRenderer.render(renderer, db, configuration); // then: assertThat(renderResponse).isEqualTo(2); }
@Test public void shouldThrowAnExceptionWithCollectedErrorMessages() throws Exception { String fakeExceptionMessage = "fake exception"; // expect exception.expect(RenderingException.class); exception.expectMessage(fakeExceptionMessage + "\n" + fakeExceptionMessage); // given DocumentTypes.addDocumentType("customType"); DocumentList documentList = new DocumentList(); HashMap<String, Object> document = emptyDocument(); HashMap<String, Object> document2 = emptyDocument(); documentList.add(document); documentList.add(document2); // throw an exception for every call of renderer's render method doThrow(new Exception(fakeExceptionMessage)).when(renderer).render(ArgumentMatchers.<String, Object>anyMap()); when(db.getUnrenderedContent(anyString())).thenReturn(emptyDocumentList); when(db.getUnrenderedContent("customType")).thenReturn(documentList); // when int renderResponse = documentsRenderer.render(renderer, db, configuration); // then assertThat(renderResponse).isEqualTo(2); }
public static DocumentList wrap(Iterator<ODocument> docs) { DocumentList list = new DocumentList(); while (docs.hasNext()) { ODocument next = docs.next(); list.add(DBUtil.documentToModel(next)); } return list; }