@Override public Health check() { if (isConnectedToDB()) { return Health.GREEN; } return RED_HEALTH; }
@Test public void status_is_GREEN_without_cause_if_isAlive_returns_1() { when(isAliveMapper.isAlive()).thenReturn(1); Health health = underTest.check(); assertThat(health).isEqualTo(Health.GREEN); }
@Test public void status_is_RED_with_single_cause_if_any_error_occurs_when_checking_DB() { when(isAliveMapper.isAlive()).thenThrow(new RuntimeException("simulated runtime exception when querying DB")); Health health = underTest.check(); verifyRedStatus(health); }
@Override public Health check() { if (isConnectedToDB()) { return Health.GREEN; } return RED_HEALTH; }
/** * By contract {@link IsAliveMapper#isAlive()} can not return anything but 1. Still we write this test as a * protection against change in this contract. */ @Test public void status_is_RED_with_single_cause_if_isAlive_does_not_return_1() { when(isAliveMapper.isAlive()).thenReturn(12); Health health = underTest.check(); verifyRedStatus(health); }