ExpressionFunctionUtils { static MethodDeclaration getFieldRefExpressionMethodDeclaration(final String methodName, final FieldRef fieldRef, final ClassOrInterfaceType returnedType, final LinkedHashMap<String, ClassOrInterfaceType> parameterNameTypeMap) { String variableName = "fieldRefVariable"; final BlockStmt body; if (parameterNameTypeMap.size() == 1) { body = getFieldRefExpressionFromCommonDataBlockStmt(variableName, fieldRef, returnedType, parameterNameTypeMap); } else { body = getFieldRefExpressionFromDefineFunctionBlockStmt(variableName, fieldRef, returnedType, parameterNameTypeMap); } return getExpressionMethodDeclaration(methodName, variableName, body, returnedType, parameterNameTypeMap); } private  ExpressionFunctionUtils();   }
@Test public void getFieldRefExpressionMethodDeclaration() { int methodArity = new Random().nextInt(20); FieldRef fieldRef = fieldRefSupplier.get(); String methodName = String.format(METHOD_NAME_TEMPLATE, fieldRef.getClass().getSimpleName(), methodArity); MethodDeclaration retrieved = ExpressionFunctionUtils.getFieldRefExpressionMethodDeclaration(methodName, fieldRef, STRING_CLASS, DEFAULT_PARAMETERTYPE_MAP); String expected = String.format("java.lang.String fieldRefVariable = (java.lang.String) kiePMMLNameValue.map" + "(%1$s::getValue).orElse(%2$s);", KiePMMLNameValue.class.getName(), fieldRef.getMapMissingTo()); commonValidateFieldRefMethod(retrieved, methodName, expected, String.class.getName()); fieldRef.setMapMissingTo("MAP_MISSING_TO"); methodName = String.format(METHOD_NAME_TEMPLATE, fieldRef.getClass().getSimpleName(), methodArity); retrieved = ExpressionFunctionUtils.getFieldRefExpressionMethodDeclaration(methodName, fieldRef, STRING_CLASS, DEFAULT_PARAMETERTYPE_MAP); expected = String.format("java.lang.String fieldRefVariable = (java.lang.String) kiePMMLNameValue.map" + "(%1$s::getValue).orElse(\"%2$s\");", KiePMMLNameValue.class.getName(), fieldRef.getMapMissingTo()); commonValidateFieldRefMethod(retrieved, methodName, expected, String.class.getName()); }