### Question:
ArchivedCaseDatastore extends CommonDatastore<ArchivedCaseItem, ArchivedProcessInstance> implements DatastoreHasGet<ArchivedCaseItem>,
DatastoreHasSearch<ArchivedCaseItem>, DatastoreHasDelete { @Override public void delete(final List<APIID> ids) { try { final ProcessAPI processAPI = getProcessApi(); final List<Long> toDeleteIds = new ArrayList<Long>(); for (final APIID apiId : ids) { final ArchivedProcessInstance archivedProcessInstance = processAPI.getArchivedProcessInstance(apiId.toLong()); toDeleteIds.add(archivedProcessInstance.getSourceObjectId()); } processAPI.deleteArchivedProcessInstancesInAllStates(toDeleteIds); } catch (final Exception e) { throw new APIException(e); } } ArchivedCaseDatastore(final APISession engineSession); @Override ItemSearchResult<ArchivedCaseItem> search(final int page, final int resultsByPage, final String search, final String orders,
            final Map<String, String> filters); @Override ArchivedCaseItem get(final APIID id); ArchivedCaseItem getUsingSourceObjectId(final APIID id); @Override void delete(final List<APIID> ids); ProcessAPI getProcessApi();  }### Answer:
@Test public void should_delete_archive_case_call_right_engine_method() throws DeletionException, ArchivedProcessInstanceNotFoundException, ProcessInstanceNotFoundException { final List<APIID> idList = Arrays.asList(APIID.makeAPIID(archivedProcessInstanceId1), APIID.makeAPIID(archivedProcessInstanceId2), APIID.makeAPIID(archivedProcessInstanceId3)); datastore.delete(idList); verify(processAPI, times(3)).getArchivedProcessInstance(anyLong()); verify(processAPI).deleteArchivedProcessInstancesInAllStates( Arrays.asList( sourceProcessInstanceId1, sourceProcessInstanceId2, sourceProcessInstanceId3) ); }
@Test public void should_delete_all_archived_cases_when_one_id_is_given() throws DeletionException, ProcessInstanceNotFoundException, ArchivedProcessInstanceNotFoundException { final List<APIID> idList = Collections.singletonList(APIID.makeAPIID(archivedProcessInstanceId1)); datastore.delete(idList); verify(processAPI).getArchivedProcessInstance(archivedProcessInstanceId1); verify(processAPI, times(1)).getArchivedProcessInstance(archivedProcessInstanceId1); verify(processAPI).deleteArchivedProcessInstancesInAllStates(Collections.singletonList(sourceProcessInstanceId1)); }
@Test(expected = APIException.class) public void should_throw_an_api_exception_when_deletion_exception_is_rised() throws DeletionException { doThrow(new DeletionException("exception!")).when(processAPI).deleteArchivedProcessInstancesInAllStates(anyList()); final List<APIID> idList = Collections.singletonList(APIID.makeAPIID(archivedProcessInstanceId1)); datastore.delete(idList); }