### Question:
CaseDocumentDatastore extends CommonDatastore<CaseDocumentItem, Document> implements DatastoreHasAdd<CaseDocumentItem>,
DatastoreHasGet<CaseDocumentItem>,
DatastoreHasUpdate<CaseDocumentItem>, DatastoreHasDelete { protected DocumentValue buildDocumentValueFromUploadPath(final String uploadPath, final int index, String fileName) throws DocumentException, IOException { String mimeType = null; byte[] fileContent = null; if (uploadPath != null) { final File theSourceFile = tenantFolder.getTempFile(uploadPath, getEngineSession().getTenantId()); if (theSourceFile.exists()) { if (theSourceFile.length() > maxSizeForTenant * 1048576) { final String errorMessage = "This document is exceeded " + maxSizeForTenant + "Mb"; throw new DocumentException(errorMessage); } fileContent = DocumentUtil.getArrayByteFromFile(theSourceFile); if (theSourceFile.isFile()) { if (StringUtil.isBlank(fileName)) { fileName = theSourceFile.getName(); } mimeType = mimetypesFileTypeMap.getContentType(theSourceFile); } } else { throw new FileNotFoundException("Cannot find " + uploadPath + " in the tenant temp directory."); } } final DocumentValue documentValue = new DocumentValue(fileContent, mimeType, fileName); if (index != -1) { documentValue.setIndex(index); } return documentValue; } CaseDocumentDatastore(final APISession engineSession, final WebBonitaConstantsUtils constantsValue, final ProcessAPI processAPI,
            final BonitaHomeFolderAccessor tenantFolder); @Override CaseDocumentItem get(final APIID id); @Override CaseDocumentItem add(final CaseDocumentItem item); @Override CaseDocumentItem update(final APIID id, final Map<String, String> attributes); ItemSearchResult<CaseDocumentItem> search(final int page, final int resultsByPage,
            final String search, final Map<String, String> filters, final String orders); @Override void delete(final List<APIID> ids);  }### Answer:
@Test public void it_should_create_documentvalue_with_given_filename() throws DocumentException, IOException { final URL docUrl = getClass().getResource("/doc.jpg"); when(tenantFolder.getTempFile(docUrl.getPath(), 1L)).thenReturn(new File(docUrl.getPath())); final DocumentValue documentValue = documentDatastore.buildDocumentValueFromUploadPath(docUrl.getPath(), 1, "fileName"); assertTrue(documentValue.getFileName().equals("fileName")); }
@Test public void it_should_create_documentvalue_with_name_of_the_uploaded_file() throws DocumentException, IOException { final URL docUrl = getClass().getResource("/doc.jpg"); when(tenantFolder.getTempFile(docUrl.getPath(), 1L)).thenReturn(new File(docUrl.getPath())); final DocumentValue documentValue = documentDatastore.buildDocumentValueFromUploadPath(docUrl.getPath(), 1, ""); assertTrue(documentValue.getFileName().equals("doc.jpg")); }