ActivitiHelper { public Boolean getExpressionVariableAsBoolean(Expression expression, DelegateExecution execution, String variableName, boolean isRequired, Boolean defaultValue) throws IllegalArgumentException { Boolean variableBoolean = defaultValue; String variableString = getExpressionVariableAsString(expression, execution); if (isRequired && StringUtils.isBlank(variableString)) { throw new IllegalArgumentException("\"" + variableName + "\" must be specified."); } if (isRequired || StringUtils.isNotBlank(variableString)) { String variableStringTrimmed = variableString.trim(); if (variableStringTrimmed.equalsIgnoreCase(Boolean.TRUE.toString()) || variableStringTrimmed.equalsIgnoreCase(Boolean.FALSE.toString())) { variableBoolean = Boolean.valueOf(variableStringTrimmed); } else { throw new IllegalArgumentException("\"" + variableName + "\" must be a valid boolean value of \"true\" or \"false\"."); } } return variableBoolean; }  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 testGetExpressionVariableAsBoolean() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BOOLEAN_VALUE.toString()); Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE); assertEquals(BOOLEAN_VALUE, result); }
@Test public void testGetExpressionVariableAsBooleanBlankValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BLANK_TEXT); Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, BOOLEAN_DEFAULT_VALUE); assertEquals(BOOLEAN_DEFAULT_VALUE, result); }
@Test public void testGetExpressionVariableAsBooleanInvalidValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(INVALID_VALUE); try { activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("\"%s\" must be a valid boolean value of \"true\" or \"false\".", VARIABLE_NAME), e.getMessage()); } }
@Test public void testGetExpressionVariableAsBooleanRequired() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BOOLEAN_VALUE.toString()); Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE); assertEquals(BOOLEAN_VALUE, result); }
@Test public void testGetExpressionVariableAsBooleanRequiredBlankValue() { Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BLANK_TEXT); try { activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("\"%s\" must be specified.", VARIABLE_NAME), e.getMessage()); } }