@Test
public void getFilteredKiePMMLNameValueExpression() {

    String kiePMMLNameValueListParam = "KIEPMMLNAMEVALUELISTPARAM";
    String fieldNameToRef = "FIELDNAMETOREF";
    ExpressionStmt retrieved = CommonCodegenUtils.getFilteredKiePMMLNameValueExpression(kiePMMLNameValueListParam, fieldNameToRef, true);
    assertNotNull(retrieved);
    String expected = String.format("%1$s<%2$s> %3$s = %4$s.stream().filter((%2$s %5$s) -> %6$s.equals(\"%7$s\", %5$s.getName())).findFirst();",
                                    Optional.class.getName(),
                                    KiePMMLNameValue.class.getName(),
                                    OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME,
                                    kiePMMLNameValueListParam,
                                    LAMBDA_PARAMETER_NAME,
                                    Objects.class.getName(),
                                    fieldNameToRef);
    String retrievedString = retrieved.toString();
    assertEquals(expected, retrievedString);
    BlockStmt body = new BlockStmt();
    body.addStatement(retrieved);
    Parameter listParameter = new Parameter(CommonCodegenUtils.getTypedClassOrInterfaceType(List.class.getName(), Collections.singletonList(KiePMMLNameValue.class.getName())), kiePMMLNameValueListParam);
    Parameter fieldRefParameter = new Parameter(parseClassOrInterfaceType(String.class.getName()), fieldNameToRef);
    commonValidateCompilation(body, Arrays.asList(listParameter, fieldRefParameter));
    //
    retrieved = CommonCodegenUtils.getFilteredKiePMMLNameValueExpression(kiePMMLNameValueListParam, fieldNameToRef, false);
    assertNotNull(retrieved);
    expected = String.format("%1$s<%2$s> %3$s = %4$s.stream().filter((%2$s %5$s) -> %6$s.equals(%7$s, %5$s.getName())).findFirst();",
                                    Optional.class.getName(),
                                    KiePMMLNameValue.class.getName(),
                                    OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME,
                                    kiePMMLNameValueListParam,
                                    LAMBDA_PARAMETER_NAME,
                                    Objects.class.getName(),
                                    fieldNameToRef);
    retrievedString = retrieved.toString();
    assertEquals(expected, retrievedString);
    body = new BlockStmt();
    body.addStatement(retrieved);
    listParameter = new Parameter(CommonCodegenUtils.getTypedClassOrInterfaceType(List.class.getName(), Collections.singletonList(KiePMMLNameValue.class.getName())), kiePMMLNameValueListParam);
    fieldRefParameter = new Parameter(parseClassOrInterfaceType(String.class.getName()), fieldNameToRef);
    commonValidateCompilation(body, Arrays.asList(listParameter, fieldRefParameter));
}