ActivitiHelper { public Integer getExpressionVariableAsInteger(Expression expression, DelegateExecution execution, String variableName, boolean isRequired) throws IllegalArgumentException { Integer variableInteger = null; String variableString = getExpressionVariableAsString(expression, execution); if (isRequired && StringUtils.isBlank(variableString)) { throw new IllegalArgumentException("\"" + variableName + "\" must be specified."); } if (isRequired || StringUtils.isNotBlank(variableString)) { try { variableInteger = Integer.parseInt(getExpressionVariableAsString(expression, execution)); } catch (Exception ex) { throw new IllegalArgumentException("\"" + variableName + "\" must be a valid integer value.", ex); } } return variableInteger; }  String getProcessIdentifyingInformation(DelegateExecution execution); Object getExpressionVariable(Expression expression, DelegateExecution execution); String getExpressionVariableAsString(Expression expression, DelegateExecution execution); String getRequiredExpressionVariableAsString(Expression expression, DelegateExecution execution, String variableName); Integer getExpressionVariableAsInteger(Expression expression, DelegateExecution execution, String variableName, boolean isRequired); Boolean getExpressionVariableAsBoolean(Expression expression, DelegateExecution execution, String variableName, boolean isRequired,
        Boolean defaultValue); BpmnModel constructBpmnModelFromXmlAndValidate(String xmlString);  }
@Test public void testGetExpressionVariableAsInteger() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(INTEGER_VALUE.toString()); Integer result = activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED); assertEquals(INTEGER_VALUE, result); }
@Test public void testGetExpressionVariableAsIntegerBlankValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BLANK_TEXT); Integer result = activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED); assertNull(result); }
@Test public void testGetExpressionVariableAsIntegerInvalidValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(INVALID_VALUE); try { activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("\"%s\" must be a valid integer value.", VARIABLE_NAME), e.getMessage()); } }
@Test public void testGetExpressionVariableAsIntegerRequired() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(INTEGER_VALUE.toString()); Integer result = activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED); assertEquals(INTEGER_VALUE, result); }
@Test public void testGetExpressionVariableAsIntegerRequiredBlankValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BLANK_TEXT); try { activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("\"%s\" must be specified.", VARIABLE_NAME), e.getMessage()); } }