### Question:
AuthorityGetCaptchaGateway extends BaseApiGateway { public void newCaptchaId(Callback callback) { apiGateway.makeRequest(new AuthGetCaptchaRequest(), new AuthorityGetCaptchaCallback(callback, this, douban)); } AuthorityGetCaptchaGateway(Douban douban, ApiGateway apiGateway); void newCaptchaId(Callback callback); static final Gson GSON; }### Answer:
@Test public void shouldCallOnFailureWhenResponseBodyEmpty() throws Exception { authorityGetCaptchaGateway.newCaptchaId(new Callback()); apiGateway.simulateTextResponse(200, TestResponses.NULL_RESP, null); assertNotNull(authorityGetCaptchaGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(),equalTo(ApiInternalError.INTERNAL_ERROR.getCode())); }
@Test public void shouldCallOnFailureWhenCallerError() throws Exception { authorityGetCaptchaGateway.newCaptchaId(badCallback); apiGateway.simulateTextResponse(200, TestResponses.NEW_CAPTCHA, null); assertNotNull(authorityGetCaptchaGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(),equalTo(ApiInternalError.CALLER_ERROR.getCode())); }
@Test public void shouldMakeARemoteCallWhenFetchNewCaptchaId() { authorityGetCaptchaGateway.newCaptchaId(new Callback()); String urlString = apiGateway.getLatestRequest().getUrlString(); assertThat(urlString, equalTo("http: }
@Test public void shouldReturnNewCaptchaId() throws Exception { authorityGetCaptchaGateway.newCaptchaId(new Callback()); apiGateway.simulateTextResponse(200, TestResponses.NEW_CAPTCHA, null); assertThat(douban.captchaImageUrl, equalTo(Constants.CAPTCHA_URL + "&id=8Z9w6tODHEukHkAmBz52dWg4:en")); }
@Test public void shouldCallOnFailureWhenParseRespError() throws Exception { authorityGetCaptchaGateway.newCaptchaId(new Callback()); apiGateway.simulateTextResponse(200, TestResponses.ERROR_RESP, null); assertNotNull(authorityGetCaptchaGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(),equalTo(ApiInternalError.INTERNAL_ERROR.getCode())); }