@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); }
documents.add(simpleDocument(fourth)); documents.add(simpleDocument(third)); documents.add(simpleDocument(second)); documents.add(simpleDocument(first)); Map<String, Object> fourthDoc = simpleDocument(fourth); fourthDoc.put("previousContent", simpleDocument(third)); fourthDoc.put("nextContent", null); Map<String, Object> thirdDoc = simpleDocument(third); thirdDoc.put("nextContent", simpleDocument(fourth)); thirdDoc.put("previousContent", simpleDocument(second)); Map<String, Object> secondDoc = simpleDocument(second); secondDoc.put("nextContent", simpleDocument(third)); secondDoc.put("previousContent", simpleDocument(first)); Map<String, Object> firstDoc = simpleDocument(first); firstDoc.put("nextContent", simpleDocument(second)); firstDoc.put("previousContent", null);
@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); }