### Question:
ProcessFormService { public boolean isAllowedToStartProcess(final APISession apiSession, final long processDefinitionId, final long enforcedUserId) throws BonitaException { if (ActivationState.ENABLED.equals(getProcessAPI(apiSession).getProcessDeploymentInfo(processDefinitionId).getActivationState())) { final Map<String, Serializable> parameters = new HashMap<String, Serializable>(); parameters.put("USER_ID_KEY", enforcedUserId); parameters.put("PROCESS_DEFINITION_ID_KEY", processDefinitionId); return (Boolean) getCommandAPI(apiSession).execute("canStartProcessDefinition", parameters); } return false; }  String getProcessPath(final APISession apiSession, final long processDefinitionId); String encodePathSegment(final String stringToEncode); long getProcessDefinitionId(final APISession apiSession, final String processName, final String processVersion); long getTaskInstanceId(final APISession apiSession, final long processInstanceId, final String taskName, final long userId); String getTaskName(final APISession apiSession, final long taskInstanceId); long ensureProcessDefinitionId(final APISession apiSession, final long processDefinitionId, final long processInstanceId, final long taskInstanceId); boolean isAllowedToSeeTask(final APISession apiSession, final long taskInstanceId, final long enforcedUserId,
            final boolean assignTask); boolean isAllowedToSeeProcessInstance(final APISession apiSession, final long processInstanceId,
            final long enforcedUserId); boolean isAllowedToStartProcess(final APISession apiSession, final long processDefinitionId, final long enforcedUserId); boolean isAllowedAsAdminOrProcessSupervisor(final HttpServletRequest request, final APISession apiSession, final long processDefinitionId,
            final long taskInstanceId, final long userId, final boolean assignTask);  }### Answer:
@Test public void isAllowedToStartProcess_should_return_true() throws Exception { final Map<String, Serializable> parameters = new HashMap<String, Serializable>(); parameters.put("USER_ID_KEY", 1L); parameters.put("PROCESS_DEFINITION_ID_KEY", 42L); when(commandAPI.execute("canStartProcessDefinition", parameters)).thenReturn(true); final ProcessDeploymentInfo processDeploymentInfo = mock(ProcessDeploymentInfo.class); when(processDeploymentInfo.getActivationState()).thenReturn(ActivationState.ENABLED); when(processAPI.getProcessDeploymentInfo(42L)).thenReturn(processDeploymentInfo); final boolean isAllowedToStartProcess = processFormService.isAllowedToStartProcess(apiSession, 42L, 1L); assertTrue(isAllowedToStartProcess); }
@Test public void isAllowedToStartProcess_should_return_false() throws Exception { final Map<String, Serializable> parameters = new HashMap<String, Serializable>(); parameters.put("USER_ID_KEY", 1L); parameters.put("PROCESS_DEFINITION_ID_KEY", 42L); when(commandAPI.execute("canStartProcessDefinition", parameters)).thenReturn(false); final ProcessDeploymentInfo processDeploymentInfo = mock(ProcessDeploymentInfo.class); when(processDeploymentInfo.getActivationState()).thenReturn(ActivationState.ENABLED); when(processAPI.getProcessDeploymentInfo(42L)).thenReturn(processDeploymentInfo); final boolean isAllowedToStartProcess = processFormService.isAllowedToStartProcess(apiSession, 42L, 1L); assertFalse(isAllowedToStartProcess); }
@Test public void isAllowedToStartProcess_should_return_false_if_process_not_enabled() throws Exception { final ProcessDeploymentInfo processDeploymentInfo = mock(ProcessDeploymentInfo.class); when(processDeploymentInfo.getActivationState()).thenReturn(ActivationState.DISABLED); when(processAPI.getProcessDeploymentInfo(42L)).thenReturn(processDeploymentInfo); final boolean isAllowedToStartProcess = processFormService.isAllowedToStartProcess(apiSession, 42L, 1L); assertFalse(isAllowedToStartProcess); }