### Question:
QualityService { ScenarioCountDTO countScenariosOfSeverity(Set<Run> runs, Severity severity) { ScenarioCountDTO counts = new ScenarioCountDTO(); for (Run run : runs) { for (ExecutedScenario executedScenario : run.getExecutedScenarios()) { if (Severity.ALL.equals(severity) || (StringUtils.isEmpty(executedScenario.getSeverity()) && severity.isDefaultOnMissing()) || severity.getCode().equals(executedScenario.getSeverity())) { countScenario(counts, executedScenario); } } } return counts; }  void computeQuality(Execution execution);  }### Answer:
@Test public void countScenariosOfSeverity_should_count_all() { final Set<Run> runs = Collections.singleton(run() .withExecutedScenarios(new HashSet<>(Arrays.asList( passedScenario(), failedScenario())))); ScenarioCountDTO counts = cut.countScenariosOfSeverity(runs, Severity.ALL); assertThat(counts.getTotal()).isEqualTo(2); assertThat(counts.getPassed()).isEqualTo(1); assertThat(counts.getFailed()).isEqualTo(1); }
@Test public void countScenariosOfSeverity_should_count_default() { final Set<Run> runs = Collections.singleton(run() .withExecutedScenarios(new HashSet<>(Arrays.asList( passedScenario().withSeverity(""), failedScenario().withSeverity("some"), failedScenario().withSeverity("other"))))); Severity someSeverity = new Severity().withCode("some").withDefaultOnMissing(true); ScenarioCountDTO counts = cut.countScenariosOfSeverity(runs, someSeverity); assertThat(counts.getTotal()).isEqualTo(2); assertThat(counts.getPassed()).isEqualTo(1); assertThat(counts.getFailed()).isEqualTo(1); }
@Test public void countScenariosOfSeverity_should_count_only_the_given_severity() { final Set<Run> runs = Collections.singleton(run() .withExecutedScenarios(new HashSet<>(Arrays.asList( passedScenario().withSeverity(""), failedScenario().withSeverity("some"))))); Severity someSeverity = new Severity().withCode("some"); ScenarioCountDTO counts = cut.countScenariosOfSeverity(runs, someSeverity); assertThat(counts.getTotal()).isEqualTo(1); assertThat(counts.getPassed()).isEqualTo(0); assertThat(counts.getFailed()).isEqualTo(1); }