@Test public void testParamIsNullError() throws Exception { ConditionGenerator generator = new ConditionGenerator(); Condition condition = new Condition("startsWith"); condition.addParam("variable"); condition.addParam(null); expectedException.expectMessage("Parameter can not be null nor empty"); generator.generateScript(condition); }
public String generateScript(Condition condition) throws GenerateConditionException { if (condition == null) { throw new GenerateConditionException(MISSING_CONDITION_ERROR); } if (!isValidFunction(condition.getFunction())) { throw new GenerateConditionException(MessageFormat.format(FUNCTION_NOT_FOUND_ERROR, condition.getFunction())); } final String function = condition.getFunction().trim(); final StringBuilder script = new StringBuilder(); script.append("return "); script.append(ConditionParser.KIE_FUNCTIONS); script.append(function); script.append("("); boolean first = true; for (String param : condition.getParams()) { if (param == null || param.isEmpty()) { throw new GenerateConditionException(PARAMETER_NULL_EMPTY); } if (first) { script.append(param); first = false; } else { script.append(", "); script.append("\""); script.append(escapeJavaNonUTFChars(param)); script.append("\""); } } script.append(");"); return script.toString(); }
ConditionGenerator { public String generateScript(Condition condition) throws GenerateConditionException { if (condition == null) { throw new GenerateConditionException(MISSING_CONDITION_ERROR); } if (!isValidFunction(condition.getFunction())) { throw new GenerateConditionException(MessageFormat.format(FUNCTION_NOT_FOUND_ERROR, condition.getFunction())); } final String function = condition.getFunction().trim(); final StringBuilder script = new StringBuilder(); script.append("return "); script.append(ConditionParser.KIE_FUNCTIONS); script.append(function); script.append("("); boolean first = true; for (String param : condition.getParams()) { if (param == null || param.isEmpty()) { throw new GenerateConditionException(PARAMETER_NULL_EMPTY); } if (first) { script.append(param); first = false; } else { script.append(", "); script.append("\""); script.append(escapeJavaNonUTFChars(param)); script.append("\""); } } script.append(");"); return script.toString(); } }
ConditionGenerator { public String generateScript(Condition condition) throws GenerateConditionException { if (condition == null) { throw new GenerateConditionException(MISSING_CONDITION_ERROR); } if (!isValidFunction(condition.getFunction())) { throw new GenerateConditionException(MessageFormat.format(FUNCTION_NOT_FOUND_ERROR, condition.getFunction())); } final String function = condition.getFunction().trim(); final StringBuilder script = new StringBuilder(); script.append("return "); script.append(ConditionParser.KIE_FUNCTIONS); script.append(function); script.append("("); boolean first = true; for (String param : condition.getParams()) { if (param == null || param.isEmpty()) { throw new GenerateConditionException(PARAMETER_NULL_EMPTY); } if (first) { script.append(param); first = false; } else { script.append(", "); script.append("\""); script.append(escapeJavaNonUTFChars(param)); script.append("\""); } } script.append(");"); return script.toString(); }  }
ConditionGenerator { public String generateScript(Condition condition) throws GenerateConditionException { if (condition == null) { throw new GenerateConditionException(MISSING_CONDITION_ERROR); } if (!isValidFunction(condition.getFunction())) { throw new GenerateConditionException(MessageFormat.format(FUNCTION_NOT_FOUND_ERROR, condition.getFunction())); } final String function = condition.getFunction().trim(); final StringBuilder script = new StringBuilder(); script.append("return "); script.append(ConditionParser.KIE_FUNCTIONS); script.append(function); script.append("("); boolean first = true; for (String param : condition.getParams()) { if (param == null || param.isEmpty()) { throw new GenerateConditionException(PARAMETER_NULL_EMPTY); } if (first) { script.append(param); first = false; } else { script.append(", "); script.append("\""); script.append(escapeJavaNonUTFChars(param)); script.append("\""); } } script.append(");"); return script.toString(); }  String generateScript(Condition condition); }
ConditionGenerator { public String generateScript(Condition condition) throws GenerateConditionException { if (condition == null) { throw new GenerateConditionException(MISSING_CONDITION_ERROR); } if (!isValidFunction(condition.getFunction())) { throw new GenerateConditionException(MessageFormat.format(FUNCTION_NOT_FOUND_ERROR, condition.getFunction())); } final String function = condition.getFunction().trim(); final StringBuilder script = new StringBuilder(); script.append("return "); script.append(ConditionParser.KIE_FUNCTIONS); script.append(function); script.append("("); boolean first = true; for (String param : condition.getParams()) { if (param == null || param.isEmpty()) { throw new GenerateConditionException(PARAMETER_NULL_EMPTY); } if (first) { script.append(param); first = false; } else { script.append(", "); script.append("\""); script.append(escapeJavaNonUTFChars(param)); script.append("\""); } } script.append(");"); return script.toString(); }  String generateScript(Condition condition);  }