@Test
public void addMapPopulation() {

    final Map<String, MethodDeclaration> toAdd = IntStream.range(0, 5).boxed().collect(Collectors.toMap(index -> "KEY_" + index, index -> getMethodDeclaration("METHOD_" + index)));
    BlockStmt body = new BlockStmt();
    String mapName = "MAP_NAME";
    CommonCodegenUtils.addMapPopulation(toAdd, body, mapName);
    NodeList<Statement> statements = body.getStatements();
    assertEquals(toAdd.size(), statements.size());
    for (Statement statement : statements) {
        assertTrue(statement instanceof ExpressionStmt);
        ExpressionStmt expressionStmt = (ExpressionStmt) statement;
        com.github.javaparser.ast.expr.Expression expression = expressionStmt.getExpression();
        assertTrue(expression instanceof MethodCallExpr);
        MethodCallExpr methodCallExpr = (MethodCallExpr) expression;
        final NodeList<com.github.javaparser.ast.expr.Expression> arguments = methodCallExpr.getArguments();
        assertEquals(2, arguments.size());
        assertTrue(arguments.get(0) instanceof StringLiteralExpr);
        assertTrue(arguments.get(1) instanceof MethodReferenceExpr);
        MethodReferenceExpr methodReferenceExpr = (MethodReferenceExpr) arguments.get(1);
        assertTrue(methodReferenceExpr.getScope() instanceof ThisExpr);
        final com.github.javaparser.ast.expr.Expression scope = methodCallExpr.getScope().orElse(null);
        assertNotNull(scope);
        assertTrue(scope instanceof NameExpr);
        assertEquals(mapName, ((NameExpr) scope).getNameAsString());
    }
    for (Map.Entry<String, MethodDeclaration> entry : toAdd.entrySet()) {
        int matchingDeclarations = (int) statements.stream().filter(statement -> {
            ExpressionStmt expressionStmt = (ExpressionStmt) statement;
            com.github.javaparser.ast.expr.Expression expression = expressionStmt.getExpression();
            MethodCallExpr methodCallExpr = (MethodCallExpr) expression;
            final NodeList<com.github.javaparser.ast.expr.Expression> arguments = methodCallExpr.getArguments();
            if (!entry.getKey().equals(((StringLiteralExpr) arguments.get(0)).getValue())) {
                return false;
            }
            MethodReferenceExpr methodReferenceExpr = (MethodReferenceExpr) arguments.get(1);
            return entry.getValue().getName().asString().equals(methodReferenceExpr.getIdentifier());
        }).count();
        assertEquals(1, matchingDeclarations);
    }
}