### Question:
SongsGateway extends BaseApiGateway { public void querySongsByChannelId(ReportType songType, String currentSongId, int playTime, int channelId, BitRate bitRate, Callback callback) { if(channelId== ChannelConstantIds.PRIVATE_CHANNEL ||channelId== ChannelConstantIds.FAV){ this.isAuthRequire=true; } apiGateway.makeRequest(new SongsRequest(channelId, bitRate, songType,currentSongId, playTime), new SongApiResponseCallback(callback, this, douban)); } SongsGateway(Douban douban, ApiGateway apiGateway); void querySongsByChannelId(ReportType songType, String currentSongId, int playTime, int channelId, BitRate bitRate, Callback callback); static final Gson GSON; }### Answer:
@Test public void shouldReturnSongsOfChannel() throws Exception { songsGateway.querySongsByChannelId(ReportType.NEXT_QUEUE, "1", 10, ChannelConstantIds.PRIVATE_CHANNEL,BitRate.HIGH, new Callback()); apiGateway.simulateTextResponse(200, TestResponses.ROCK_CHANNELS_SONGS_JSON, null); assertNotNull(Douban.songs); assertThat(Douban.songs.size(), equalTo(2)); assertThat(Douban.songs.get(0).aid, equalTo("25779410")); }
@Test public void shouldCallOnFailureWhenParseRespError() throws Exception { songsGateway.querySongsByChannelId(ReportType.NEXT_QUEUE, "1", 10, ChannelConstantIds.PRIVATE_CHANNEL, BitRate.HIGH, new Callback()); apiGateway.simulateTextResponse(200, TestResponses.NULL_RESP, null); TestCase.assertNotNull(songsGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(), equalTo(ApiInternalError.INTERNAL_ERROR.getCode())); }
@Test public void shouldCallOnFailureWhenCallerErrorWithABadCallback() throws Exception { songsGateway.querySongsByChannelId(ReportType.NEXT_QUEUE, "1", 10, ChannelConstantIds.PRIVATE_CHANNEL, BitRate.HIGH,badCallback); apiGateway.simulateTextResponse(200, TestResponses.ROCK_CHANNELS_SONGS_JSON, null); TestCase.assertNotNull(songsGateway.failureResponse); assertThat(douban.mApiRespErrorCode.getCode(), equalTo(ApiInternalError.CALLER_ERROR.getCode())); }