### Question:
APIDocument extends ConsoleAPI<DocumentItem> { @Override public DocumentItem add(final DocumentItem item) { final long processInstanceId = Long.valueOf(item.getAttributeValue(DocumentItem.PROCESSINSTANCE_ID)); final String documentName = item.getAttributeValue(DocumentItem.DOCUMENT_NAME); final String path = item.getAttributeValue(DocumentItem.DOCUMENT_UPLOAD); final String documentCreationType = item.getAttributeValue(DocumentItem.DOCUMENT_CREATION_TYPE); final String urlPath = item.getAttributeValue(DocumentItem.DOCUMENT_URL); try { DocumentItem returnedItem = new DocumentItem(); if (processInstanceId != -1 && documentName != null && documentCreationType != null) { if (path != null && !path.isEmpty()) { returnedItem = getDataStore().createDocument(processInstanceId, documentName, documentCreationType, path, new BonitaHomeFolderAccessor()); } else if (urlPath != null && !urlPath.isEmpty()) { returnedItem = getDataStore().createDocumentFromUrl(processInstanceId, documentName, documentCreationType, urlPath); } return returnedItem; } else { throw new APIException("Error while attaching a new document. Request with bad param value."); } } catch (final UnauthorizedFolderException e) { throw new APIForbiddenException(e.getMessage()); } catch (final Exception e) { throw new APIException(e); } }  @Override DocumentItem get(final APIID id); @Override String defineDefaultSearchOrder(); @Override ItemSearchResult<DocumentItem> search(final int page, final int resultsByPage, final String search, final String orders,
            final Map<String, String> filters); @Override DocumentItem add(final DocumentItem item);  }### Answer:
@Test(expected = APIForbiddenException.class) public void should_verify_authorisation_for_the_given_document_path() throws Exception { doThrow(new UnauthorizedFolderException("error")).when(documentDatastore).createDocument(any(Long.class), any(String.class), any(String.class), any(String.class), any(BonitaHomeFolderAccessor.class)); apiDocument.add(item); }
@Test(expected = APIException.class) public void it_throws_an_exception_when_cannot_write_file_on_add() throws Exception { doThrow(new IOException("error")).when(documentDatastore).createDocument(any(Long.class), any(String.class), any(String.class), any(String.class), any(BonitaHomeFolderAccessor.class)); try { apiDocument.add(item); } catch (final APIForbiddenException e) { fail("Don't expect the APIException to be an APIForbiddenException"); } }