@Override
    public Graph toGraph(ConfigVariableExpander cve) throws InvalidIRException {
        Graph trueGraph = getTrueStatement().toGraph(cve);
        Graph falseGraph = getFalseStatement().toGraph(cve);

        // If there is nothing in the true or false sections of this if statement,
        // we can omit the if statement altogether!
        if (trueGraph.isEmpty() && falseGraph.isEmpty()) {
            return new Graph();
        }

        Graph.GraphCombinationResult combination = Graph.combine(trueGraph, falseGraph);
        Graph newGraph = combination.graph;
        Collection<Vertex> trueRoots = trueGraph.roots().map(combination.oldToNewVertices::get).collect(Collectors.toList());
        Collection<Vertex> falseRoots = falseGraph.roots().map(combination.oldToNewVertices::get).collect(Collectors.toList());

        IfVertex ifVertex = new IfVertex(this.getSourceWithMetadata(),
                (BooleanExpression) ExpressionSubstitution.substituteBoolExpression(cve, this.booleanExpression));
        newGraph.addVertex(ifVertex);

        for (Vertex v : trueRoots) {
            newGraph.chainVerticesUnsafe(BooleanEdge.trueFactory, ifVertex, v);
        }

        for (Vertex v : falseRoots) {
            newGraph.chainVerticesUnsafe(BooleanEdge.falseFactory, ifVertex, v);
        }

        return newGraph;
    }
@Test
    public void testIfWithOneTrueOneFalseStatement() throws InvalidIRException {
        ConfigVariableExpander cve = ConfigVariableExpander.withoutSecret(EnvironmentVariableProvider.defaultProvider());
        PluginDefinition pluginDef = testPluginDefinition();
        Statement trueStatement = new PluginStatement(randMeta(), pluginDef);
        Statement falseStatement = new PluginStatement(randMeta(), pluginDef);
        BooleanExpression ifExpression = createTestExpression();
        IfStatement ifStatement = new IfStatement(
                randMeta(),
                createTestExpression(),
                trueStatement,
                falseStatement
        );

        Graph ifStatementGraph = ifStatement.toGraph(cve);
        assertFalse(ifStatementGraph.isEmpty());

        Graph expected = new Graph();
        IfVertex expectedIf = DSL.gIf(randMeta(), ifExpression);
        expected.addVertex(expectedIf);

        PluginVertex expectedT = DSL.gPlugin(randMeta(), pluginDef);
        expected.chainVertices(true, expectedIf, expectedT);

        PluginVertex expectedF = DSL.gPlugin(randMeta(), pluginDef);
        expected.chainVertices(false, expectedIf, expectedF);

        assertSyntaxEquals(expected, ifStatementGraph);
    }