### Question:
RecaptchaV2Service implements CaptchaService { @Override public void verifyResponse(final String captcha) { if (!isInValidFormat(captcha)) { metricsReporter.reportFailedCaptcha(); throw CaptchaErrors.invalidCaptchaFormat("Response contains invalid characters"); } try { verify(captcha); metricsReporter.reportPassedCaptcha(); } catch (CaptchaServiceException | CaptchaClientException e) { metricsReporter.reportFailedCaptcha(); throw e; } } RecaptchaV2Service(final RecaptchaClient recaptchaClient, final CaptchaMetricsReporter metricsReporter); @Override void verifyResponse(final String captcha);  }### Answer:
@Test void should_throw_exception_when_captcha_empty() { assertThrows(CaptchaClientException.class, () -> captchaService.verifyResponse("")); }
@Test void should_throw_exception_when_captcha_misformatted() { assertThrows(CaptchaClientException.class, () -> captchaService.verifyResponse("!")); }
@Test void should_throw_exception_when_got_timeout() { given(recaptchaClient.call("good")) .willThrow(CaptchaErrors.serviceFailure("timeout", new RestClientException("timeout"))); assertThrows(CaptchaServiceException.class, () -> captchaService.verifyResponse("good")); }
@Test void should_throw_exception_when_error_received() { given(recaptchaClient.call("bad")) .willReturn(new RecaptchaVerifyResponse(false, "", "host", ImmutableList.of(RecaptchaVerifyResponse.ErrorCode.InvalidResponse))); assertThrows(CaptchaClientException.class, () -> captchaService.verifyResponse("bad")); }
@Test void should_not_throw_exception_if_ok() { given(recaptchaClient.call("good")) .willReturn(new RecaptchaVerifyResponse(true, "", "host", ImmutableList.of())); captchaService.verifyResponse("good"); }