LambdaUtil { public static Expression appendNewLambdaToOld(LambdaExpr l1, LambdaExpr l2) { ExpressionStmt l1ExprStmt = (ExpressionStmt) l1.getBody(); ExpressionStmt l2ExprStmt = (ExpressionStmt) l2.getBody(); DrlxParseUtil.RemoveRootNodeResult removeRootNodeResult = DrlxParseUtil.removeRootNode(l2ExprStmt.getExpression()); NodeWithOptionalScope<?> newExpr = (NodeWithOptionalScope<?>) removeRootNodeResult.getFirstChild(); newExpr.setScope(l1ExprStmt.getExpression()); l1.setBody(new ExpressionStmt(removeRootNodeResult.getWithoutRootNode())); return l1; } private  LambdaUtil(); static Expression appendNewLambdaToOld(LambdaExpr l1, LambdaExpr l2);  }
@Test public void appendaLambdaToOld() { LambdaExpr l1 = parseExpression("(_this) -> _this.getTimeFieldAsDate()"); LambdaExpr l2 = parseExpression("(_this) -> _this.getTime()"); Expression expected = parseExpression("(_this) -> _this.getTimeFieldAsDate().getTime()"); Expression actual = LambdaUtil.appendNewLambdaToOld(l1, l2); assertEquals(expected.toString(), actual.toString()); }
@Test public void appendTwoMethodsToLambda() { LambdaExpr l1 = parseExpression("(_this) -> _this.getDueDate()"); LambdaExpr l2 = parseExpression("(_this) -> _this.getTime().getTime()"); Expression expected = parseExpression("(_this) -> _this.getDueDate().getTime().getTime()"); Expression actual = LambdaUtil.appendNewLambdaToOld(l1, l2); assertEquals(expected.toString(), actual.toString()); }