### Question:
QualityEmailService { String getEligibilityMessage(ExecutionDTO execution) { if (!execution.isBlockingValidation()) { return "Quality for this build:"; } else if (execution.getQualityStatus().isAcceptable()) { return "The build is <b style='background-color: #19be6b; color: white; padding: 1px 2px; border-radius: 2px;'>eligible to deploy</b>" + (execution.getQualityStatus() == QualityStatus.WARNING ? " but <b style='background-color: #ffcc30; padding: 1px 2px; border-radius: 2px;'>without much margin regarding the thresholds</b>" : "") + ":"; } else { return "The build is <b style='background-color: #ed3f14; color: white; padding: 1px 2px; border-radius: 2px;'>not eligible to deploy</b>:"; } }  @Transactional(readOnly = true, noRollbackFor = Exception.class) void sendQualityEmail(long projectId, long executionId);  }### Answer:
@Test public void getEligibilityMessage_should_not_include_eligibility_status_when_not_isBlockingValidation() { ExecutionDTO execution = new ExecutionDTO().withBlockingValidation(false); final String message = cut.getEligibilityMessage(execution); assertThat(message).isEqualTo("Quality for this build:"); }
@Test public void getEligibilityMessage_should_be_eligible_when_isBlockingValidation_and_passed() { ExecutionDTO execution = new ExecutionDTO().withBlockingValidation(true).withQualityStatus(QualityStatus.PASSED); final String message = cut.getEligibilityMessage(execution); assertThat(message).contains(">eligible to deploy<"); assertThat(message).doesNotContain(">without much margin regarding the thresholds<"); }
@Test public void getEligibilityMessage_should_be_eligible_with_warning_message_when_isBlockingValidation_and_warning() { ExecutionDTO execution = new ExecutionDTO().withBlockingValidation(true).withQualityStatus(QualityStatus.WARNING); final String message = cut.getEligibilityMessage(execution); assertThat(message).contains(">eligible to deploy<"); assertThat(message).contains(">without much margin regarding the thresholds<"); }
@Test public void getEligibilityMessage_should_not_be_eligible_when_isBlockingValidation_and_failed() { ExecutionDTO execution = new ExecutionDTO().withBlockingValidation(true).withQualityStatus(QualityStatus.FAILED); final String message = cut.getEligibilityMessage(execution); assertThat(message).contains(">not eligible to deploy<"); }
@Test public void getEligibilityMessage_should_not_be_eligible_when_isBlockingValidation_and_incomplete() { ExecutionDTO execution = new ExecutionDTO().withBlockingValidation(true).withQualityStatus(QualityStatus.INCOMPLETE); final String message = cut.getEligibilityMessage(execution); assertThat(message).contains(">not eligible to deploy<"); }