### Question:
QualityService { boolean isComplete(Execution execution) { for (Run run : getRunsToIncludeInQuality(execution)) { if (run.getStatus() != JobStatus.DONE || run.getExecutedScenarios().isEmpty()) { return false; } } return true; }  void computeQuality(Execution execution);  }### Answer:
@Test public void isComplete_should_return_true_if_all_runs_are_DONE() { Execution execution = new Execution() .withRuns(new HashSet<>(Arrays.asList( run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.DONE) .withExecutedScenarios(Collections.singleton(new ExecutedScenario())), run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.DONE) .withExecutedScenarios(Collections.singleton(new ExecutedScenario()))))); boolean complete = cut.isComplete(execution); assertThat(complete).isTrue(); }
@Test public void isComplete_should_return_false_if_any_run_is_not_DONE() { Execution execution = new Execution() .withRuns(new HashSet<>(Arrays.asList( run().withIncludeInThresholds(Boolean.TRUE).withStatus(JobStatus.DONE), run().withIncludeInThresholds(Boolean.TRUE).withStatus(JobStatus.PENDING)))); boolean complete = cut.isComplete(execution); assertThat(complete).isFalse(); }
@Test public void isComplete_should_return_false_if_any_run_is_not_DONE_even_if_it_has_executedScenarios() { Execution execution = new Execution() .withRuns(new HashSet<>(Collections.singletonList( run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.PENDING) .withExecutedScenarios(new HashSet<>(Collections.singletonList(new ExecutedScenario())))))); boolean complete = cut.isComplete(execution); assertThat(complete).isFalse(); }
@Test public void isComplete_should_return_false_if_any_run_has_no_executed_scenario() { Execution execution = new Execution() .withRuns(new HashSet<>(Arrays.asList( run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.DONE) .withExecutedScenarios(new HashSet<>(Collections.singletonList(new ExecutedScenario()))), run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.DONE) .withExecutedScenarios(Collections.emptySet())))); boolean complete = cut.isComplete(execution); assertThat(complete).isFalse(); }
@Test public void isComplete_should_return_true_if_all_runs_to_include_are_DONE() { Execution execution = new Execution() .withRuns(new HashSet<>(Arrays.asList( run() .withIncludeInThresholds(Boolean.TRUE) .withStatus(JobStatus.DONE) .withExecutedScenarios(Collections.singleton(new ExecutedScenario())), run() .withIncludeInThresholds(Boolean.FALSE) .withStatus(JobStatus.PENDING)))); boolean complete = cut.isComplete(execution); assertThat(complete).isTrue(); }