DerivedFieldFunctionUtils { static MethodDeclaration getExpressionMethodDeclaration(final Expression expression, final DataType dataType, final AtomicInteger arityCounter) { final ClassOrInterfaceType returnedType = parseClassOrInterfaceType(getBoxedClassName(dataType)); int methodArity = arityCounter.addAndGet(1); if (expression instanceof Aggregate) { return getAggregatedMethodDeclaration((Aggregate) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof Apply) { return getApplyMethodDeclaration((Apply) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof Constant) { return getConstantMethodDeclaration((Constant) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof Discretize) { return getDiscretizeMethodDeclaration((Discretize) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof FieldRef) { return getFieldRefMethodDeclaration((FieldRef) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof Lag) { return getLagMethodDeclaration((Lag) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof MapValues) { return getMapValuesMethodDeclaration((MapValues) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof NormContinuous) { return getNormContinuousMethodDeclaration((NormContinuous) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof NormDiscrete) { return getNormDiscreteMethodDeclaration((NormDiscrete) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else if (expression instanceof TextIndex) { return getTextIndexMethodDeclaration((TextIndex) expression, returnedType, methodArity, DEFAULT_PARAMETERTYPE_MAP); } else { throw new IllegalArgumentException(String.format("Expression %s not managed", expression.getClass())); } } private  DerivedFieldFunctionUtils();   }
@Test(expected = IllegalArgumentException.class) public void getExpressionMethodDeclarationUnknownExpression() { Expression expression = new Expression() { @Override public VisitorAction accept(Visitor visitor) { return null; } }; DerivedFieldFunctionUtils.getExpressionMethodDeclaration(expression, DataType.STRING, new AtomicInteger()); }
@Test public void getExpressionMethodDeclarationUnsupportedExpression() { for (Supplier<Expression> supplier : unsupportedExpressionSupplier) { Expression expression = supplier.get(); try { DerivedFieldFunctionUtils.getExpressionMethodDeclaration(expression, DataType.STRING, new AtomicInteger()); fail(String.format("Expecting KiePMMLException for %s", expression.getClass())); } catch (Exception e) { assertEquals(KiePMMLException.class, e.getClass()); } } }
@Test public void getExpressionMethodDeclarationSupportedExpression() { for (Supplier<Expression> supplier : supportedExpressionSupplier) { Expression expression = supplier.get(); try { DerivedFieldFunctionUtils.getExpressionMethodDeclaration(expression, DataType.STRING, new AtomicInteger()); } catch (Exception e) { fail(String.format("Unexpected %s for %s", e, expression.getClass())); } } }