DocumentService { public void deleteDocument(DocumentMetadata document) throws DocumentServiceException { LOG.debug("Deleting a document"); if (document != null && document.getDocumentid() == null && document.getDocumentUniqueId() != null) { DocumentQueryParams params = new DocumentQueryParams(); List<String> uniqueIds = new ArrayList<>(); uniqueIds.add(document.getDocumentUniqueId()); params.setDocumentUniqueId(uniqueIds); List<DocumentMetadata> docs = documentQuery(params); if (docs != null && docs.size() == 1) { document = docs.get(0); } else { throw new DocumentServiceException( "Single document match not found for document unique id: " + document.getDocumentUniqueId()); } documentDao.delete(document); } else { if (document == null) { throw new DocumentServiceException("Document to delete was null"); } else if (document.getDocumentUniqueId() == null) { throw new DocumentServiceException("Document unique id was null"); } } }  DocumentMetadata saveDocument(DocumentMetadata document); void deleteDocument(DocumentMetadata document); DocumentMetadata getDocument(Long documentId); List<DocumentMetadata> getAllDocuments(); List<DocumentMetadata> documentQuery(DocumentQueryParams params); String getNextID();  }
@Test public void testDeleteDocument_Success() throws DocumentServiceException { final List<DocumentMetadata> DOC_LIST = new ArrayList<>(); DocumentMetadata doc = new DocumentMetadata(); String unique_id = "Doc_ID_1"; doc.setDocumentUniqueId(unique_id); DOC_LIST.add(doc); DocumentService documentService = getDocumentServiceWithMockDaos(); when(DOCUMENT_DAO.findDocuments(Mockito.isA(DocumentQueryParams.class))).thenReturn(DOC_LIST); documentService.deleteDocument(doc); verify(DOCUMENT_DAO).delete(doc); }
@Test(expected = DocumentServiceException.class) public void testDeleteDocument_NoDocumentsReturned() throws DocumentServiceException { DocumentMetadata doc = new DocumentMetadata(); String unique_id = "Doc_ID_1"; doc.setDocumentUniqueId(unique_id); DocumentService documentService = getDocumentServiceWithMockDaos(); documentService.deleteDocument(doc); }
@Test(expected = DocumentServiceException.class) public void testDeleteDocument_NullDocumentReturned() throws DocumentServiceException { DocumentMetadata nullDoc = null; DocumentService documentService = new DocumentService(); documentService.deleteDocument(nullDoc); }
@Test(expected = DocumentServiceException.class) public void testDeleteDocument_NullDocumentId() throws DocumentServiceException { DocumentMetadata doc = new DocumentMetadata(); DocumentService documentService = new DocumentService(); documentService.deleteDocument(doc); }