### Question:
JedisHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try (Jedis jedis = pool.getResource()) { final String pong = jedis.ping(); if ("PONG".equals(pong)) { return Result.healthy(); } } return Result.unhealthy("Could not ping redis"); } JedisHealthCheck(JedisPool pool);   }### Answer:
@Test public void isHealthyWhenPingCompletes() throws Exception { when(jedis.ping()).thenReturn("PONG"); assertThat(healthcheck.check()).isHealthy(); }
@Test public void isUnhealthyWhenPingFails() throws Exception { when(jedis.ping()).thenReturn("huh?"); assertThat(healthcheck.check()).isUnhealthy(); }
@Test(expected = JedisException.class) public void doesNotCatchJedisExceptions() throws Exception { when(jedis.ping()).thenThrow(new JedisException("boom")); healthcheck.check(); }
@Test(expected = JedisConnectionException.class) public void doesNotCatchJedisPoolExceptions() throws Exception { when(pool.getResource()).thenThrow(new JedisConnectionException("nope.")); healthcheck.check(); }
@Test public void returnsConnectionWhenComplete() throws Exception { when(jedis.ping()).thenReturn("PONG"); healthcheck.check(); verify(jedis).close(); }
@Test public void returnsConnectionWhenPingThrows() throws Exception { when(jedis.ping()).thenThrow(new JedisException("boom")); try { healthcheck.check(); assert_().fail("expected a JedisException, got nothing"); } catch (JedisException e) { verify(jedis).close(); } }