### Question:
ProcessInstantiationResource extends CommonResource { @Post("json") public String instantiateProcess(final Map<String, Serializable> inputs) throws ProcessDefinitionNotFoundException, ProcessActivationException, ProcessExecutionException, FileNotFoundException { final String userId = getRequestParameter(USER_PARAM); final long processDefinitionId = getProcessDefinitionIdParameter(); try { final ContractDefinition processContract = processAPI.getProcessContract(processDefinitionId); final long tenantId = apiSession.getTenantId(); final long maxSizeForTenant = PropertiesFactory.getConsoleProperties(tenantId).getMaxSize(); final Map<String, Serializable> processedInputs = typeConverterUtil.getProcessedInput(processContract, inputs, maxSizeForTenant, tenantId); long processInstanceId; if (userId == null) { processInstanceId = processAPI.startProcessWithInputs(processDefinitionId, processedInputs).getId(); } else { processInstanceId = processAPI.startProcessWithInputs(Long.parseLong(userId), processDefinitionId, processedInputs).getId(); } typeConverterUtil.deleteTemporaryFiles(inputs, tenantId); final JsonNodeFactory factory = JsonNodeFactory.instance; final ObjectNode returnedObject = factory.objectNode(); returnedObject.put(CASE_ID_ATTRIBUTE, processInstanceId); return returnedObject.toString(); } catch (final ContractViolationException e) { manageContractViolationException(e, "Cannot instantiate process task."); return null; } } ProcessInstantiationResource(final ProcessAPI processAPI, final APISession apiSession); @Post("json") String instantiateProcess(final Map<String, Serializable> inputs);  }### Answer:
@Test public void should_contract_violation_exception_log_explanations_when_logger_is_info() throws Exception { final String message = "contract violation !!!!"; final List<String> explanations = Arrays.asList("explanation1", "explanation2"); doThrow(new ContractViolationException(message, message, explanations, null)).when(processAPI) .startProcessWithInputs(anyLong(), anyMapOf(String.class, Serializable.class)); doReturn(logger).when(processInstantiationResource).getLogger(); doReturn(Long.toString(PROCESS_DEFINITION_ID)).when(processInstantiationResource).getAttribute(ProcessInstantiationResource.PROCESS_DEFINITION_ID); doReturn(contractDefinition).when(processAPI).getProcessContract(PROCESS_DEFINITION_ID); doReturn(true).when(logger).isLoggable(Level.INFO); doReturn(response).when(processInstantiationResource).getResponse(); final Map<String, Serializable> inputs = new HashMap<>(); inputs.put("testKey", "testValue"); processInstantiationResource.instantiateProcess(inputs); verify(logger, times(1)).log(Level.INFO, message + "\nExplanations:\nexplanation1explanation2"); verify(processInstantiationResource.typeConverterUtil, times(0)).deleteTemporaryFiles(anyMap(), anyLong()); }
@Test public void should_call_deleteFiles() throws ProcessDefinitionNotFoundException, FileNotFoundException, ProcessExecutionException, ProcessActivationException, ContractViolationException { doReturn(Long.toString(PROCESS_DEFINITION_ID)).when(processInstantiationResource).getAttribute(ProcessInstantiationResource.PROCESS_DEFINITION_ID); doReturn(contractDefinition).when(processAPI).getProcessContract(PROCESS_DEFINITION_ID); doReturn(response).when(processInstantiationResource).getResponse(); final Map<String, Serializable> inputs = new HashMap<>(); inputs.put("testKey", "testValue"); when(processAPI.startProcessWithInputs(PROCESS_DEFINITION_ID, inputs)).thenReturn(processInstance); processInstantiationResource.instantiateProcess(inputs); verify(processInstantiationResource.typeConverterUtil, times(1)).deleteTemporaryFiles(anyMap(), anyLong()); }