SeriesApiClient extends MarvelApiClient { public MarvelResponse<SeriesDto> getSeriesById(String seriesId) throws MarvelApiException { if (seriesId == null || seriesId.isEmpty()) { throw new IllegalArgumentException("The seriesId must not be null or empty"); } SeriesApiRest api = getApi(SeriesApiRest.class); Call<MarvelResponse<SeriesCollectionDto>> call = api.getSerie(seriesId); MarvelResponse<SeriesCollectionDto> series = execute(call); SeriesCollectionDto seriesCollectionDto = series.getResponse(); if (seriesCollectionDto != null && seriesCollectionDto.getCount() > 0) { SeriesDto seriesDto = seriesCollectionDto.getSeries().get(0); MarvelResponse<SeriesDto> serieResponse = new MarvelResponse<>(series); serieResponse.setResponse(seriesDto); return serieResponse; } else { throw new MarvelApiException("Series not found", null); } } SeriesApiClient(MarvelApiConfig marvelApiConfig); MarvelResponse<SeriesCollectionDto> getAll(int offset, int limit); MarvelResponse<SeriesCollectionDto> getAll(SeriesQuery seriesQuery); MarvelResponse<SeriesDto> getSeriesById(String seriesId); MarvelResponse<ComicsDto> getComicsBySeries(String seriesId, int offset, int limit); MarvelResponse<ComicsDto> getComicsBySeries(String seriesId, ComicsQuery comicsQuery);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptySeriesId() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); seriesApiClient.getSeriesById(INVALID_SERIES_ID); }
@Test public void shouldSendGetSeriesRequestToTheCorrectEndpoint() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getSeriesCollection.json"); seriesApiClient.getSeriesById(ANY_SERIE_ID); assertRequestSentToContains("series/" + ANY_SERIE_ID); }
@Test(expected = MarvelApiException.class) public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that series\"}"); try { seriesApiClient.getSeriesById(ANY_NOT_FOUND_ID); } catch (MarvelApiException e) { assertEquals("404", e.getMarvelCode()); assertEquals("We couldn't find that series", e.getMessage()); throw e; } }
@Test public void shouldParseGetSeriesResponse() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getSeries.json"); MarvelResponse<SeriesDto> series = seriesApiClient.getSeriesById(ANY_SERIE_ID); assertBasicMarvelResponse(series); SeriesDto response = series.getResponse(); assertIs5Ronnin(response); }