### Question:
ChannelActionGateway extends BaseApiGateway { public void favAChannel(ChannelActionType favChannel, int channelId, Callback callback) { apiGateway.makeRequest(new ChannelActionRequest(favChannel, channelId), new ChannelActionApiResponseCallbacks(callback, this, douban)); } ChannelActionGateway(Douban douban, ApiGateway apiGateway); void favAChannel(ChannelActionType favChannel, int channelId, Callback callback); static final Gson GSON; }### Answer:
@Test public void shouldReturnFavSuccess() throws Exception { channelActionGateway.favAChannel(ChannelActionType.FAV_CHANNEL, channelId, new Callback()); apiGateway.simulateTextResponse(200, TestResponses.FAV_A_CHANNEL_JSON, null); assertNull(channelActionGateway.failureResponse); assertTrue(channelActionGateway.onCompleteWasCalled); }
@Test public void shouldReturnUnFavSuccess() throws Exception { channelActionGateway.favAChannel(ChannelActionType.UNFAV_CHANNEL, channelId, new Callback()); apiGateway.simulateTextResponse(200, TestResponses.FAV_A_CHANNEL_JSON, null); assertNull(channelActionGateway.failureResponse); assertTrue(channelActionGateway.onCompleteWasCalled); }
@Test public void shouldCallOnFailureWhenParseRespError() throws Exception { channelActionGateway.favAChannel(ChannelActionType.FAV_CHANNEL, channelId, new Callback()); apiGateway.simulateTextResponse(200, TestResponses.NULL_RESP, null); assertNotNull(channelActionGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(), equalTo(ApiInternalError.INTERNAL_ERROR.getCode())); }
@Test public void shouldCallOnFailureWhenCallerError() throws Exception { channelActionGateway.favAChannel(ChannelActionType.FAV_CHANNEL, channelId, badCallback); apiGateway.simulateTextResponse(200, TestResponses.FAV_A_CHANNEL_JSON, null); assertNotNull(channelActionGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(), equalTo(ApiInternalError.CALLER_ERROR.getCode())); }