StartUpChecksPerformer { @VisibleForTesting static StartUpChecksPerformer from(StartUpCheck... checks) { return new StartUpChecksPerformer(new StartUpChecks(Sets.newHashSet(checks))); } @Inject  StartUpChecksPerformer(StartUpChecks startUpChecks); void performCheck();  }
@Test void performCheckShouldNotThrowWhenAllChecksSucceed() { StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from( fromResult(GOOD_CHECK_1), fromResult(GOOD_CHECK_2)); assertThatCode(checksPerformer::performCheck) .doesNotThrowAnyException(); }
@Test void performCheckShouldNotThrowWhenNoChecks() { StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from(); assertThatCode(checksPerformer::performCheck) .doesNotThrowAnyException(); }
@Test void performCheckShouldThrowWhenThereIsOneCheckFails() { StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from( fromResult(GOOD_CHECK_1), fromResult(GOOD_CHECK_2), fromResult(BAD_CHECK_1)); assertThatThrownBy(checksPerformer::performCheck) .isInstanceOf(StartUpChecksPerformer.StartUpChecksException.class); }
@Test void performCheckShouldThrowAnExceptionContainingAllBadChecksWhenThereAreBadChecks() { StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from( fromResult(GOOD_CHECK_1), fromResult(GOOD_CHECK_2), fromResult(BAD_CHECK_1), fromResult(BAD_CHECK_2)); assertThatThrownBy(checksPerformer::performCheck) .isInstanceOfSatisfying( StartUpChecksPerformer.StartUpChecksException.class, exception -> assertThat(exception.getBadChecks()) .containsOnly(BAD_CHECK_1, BAD_CHECK_2)); }
@Test void performCheckShouldNotPropagateUnExpectedExceptionDuringChecking() { String checkName = "throwing check name"; StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from( new StartUpCheck() { @Override public CheckResult check() { throw new RuntimeException("unexpected"); } @Override public String checkName() { return checkName; } }); assertThatThrownBy(checksPerformer::performCheck) .isInstanceOfSatisfying( StartUpChecksPerformer.StartUpChecksException.class, exception -> assertThat(exception.badCheckNames()) .containsOnly(checkName)); }