public SimulationRunMetadata build() {
        int available = 0;
        Map<String, Integer> outputCounter = new HashMap<>();
        Map<ScenarioWithIndex, Map<String, Integer>> scenarioCounter = new HashMap<>();
        AuditLog auditLog = new AuditLog();
        for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
            // this value is the same for all the scenarios
            available = scenarioResultMetadatum.getAvailable().size();
            scenarioResultMetadatum.getExecutedWithCounter()
                    .forEach((name, counter) -> outputCounter.compute(name,
                                                                      (key, number) -> number == null ? counter : number + counter));
        }

        for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
            scenarioCounter.put(scenarioResultMetadatum.getScenarioWithIndex(),
                                scenarioResultMetadatum.getExecutedWithCounter());
            auditLog.addAuditLogLines(scenarioResultMetadatum.getAuditLogLines());
        }
        return new SimulationRunMetadata(available, outputCounter.keySet().size(), outputCounter, scenarioCounter, auditLog);
    }
@Test
    public void build() {
        ScenarioWithIndex scenarioWithIndex1 = new ScenarioWithIndex(1, new Scenario());

        ScenarioResultMetadata result1 = new ScenarioResultMetadata(scenarioWithIndex1);
        result1.addExecuted("d1");
        result1.addExecuted("d2");
        result1.addAvailable("d1");
        result1.addAvailable("d2");
        result1.addAvailable("d3");

        List<DMNMessage> messagesResult1decision1 = getRandomlyGeneratedDMNMessageList();
        List<DMNMessage> messagesResult1decision2 = getRandomlyGeneratedDMNMessageList();

        Map<Integer, List<String>> expectedResult1Decision1 = fillAuditMessagesForDecision(result1, messagesResult1decision1, "d1");
        Map<Integer, List<String>> expectedResult1Decision2 = fillAuditMessagesForDecision(result1, messagesResult1decision2, "d2");

        ScenarioResultMetadata result2 = new ScenarioResultMetadata(new ScenarioWithIndex(2, new Scenario()));
        List<String> expectedDecisionsResult2 = List.of("d1", "d3");
        result2.addExecuted(expectedDecisionsResult2.get(0));
        result2.addExecuted(expectedDecisionsResult2.get(1));
        result2.addAvailable("d1");
        result2.addAvailable("d2");
        result2.addAvailable("d3");

        List<DMNMessage> messagesResult2decision1 = getRandomlyGeneratedDMNMessageList();
        List<DMNMessage> messagesResult2decision3 = getRandomlyGeneratedDMNMessageList();

        Map<Integer, List<String>> expectedResult2Decision1 = fillAuditMessagesForDecision(result1, messagesResult2decision1, "d1");
        Map<Integer, List<String>> expectedResult2Decision3 = fillAuditMessagesForDecision(result1, messagesResult2decision3, "d3");

        SimulationRunMetadataBuilder builder = SimulationRunMetadataBuilder.create();
        builder.addScenarioResultMetadata(result1);
        builder.addScenarioResultMetadata(result2);
        
        SimulationRunMetadata build = builder.build();

        assertThat(build.getAvailable()).isEqualTo(3);
        assertThat(build.getExecuted()).isEqualTo(3);
        assertThat(build.getCoveragePercentage()).isCloseTo(100, within(0.1));
        assertThat(build.getOutputCounter()).containsEntry("d1", 2).containsEntry("d2", 1);
        assertThat(build.getScenarioCounter().get(scenarioWithIndex1)).hasSize(2);
        
        AuditLog retrieved = build.getAuditLog();
        
        assertThat(retrieved).isNotNull();
        
        final List<AuditLogLine> auditLogLines = retrieved.getAuditLogLines();
        
        assertThat(auditLogLines).isNotNull().hasSize(messagesResult1decision1.size() + messagesResult1decision2.size() + messagesResult2decision1.size() + messagesResult2decision3.size());

        checkAuditLogLine(auditLogLines, expectedResult1Decision1, expectedResult1Decision2, expectedResult2Decision1, expectedResult2Decision3);
    }