ComicApiClient extends MarvelApiClient { public MarvelResponse<ComicDto> getComic(String comicId) throws MarvelApiException { if (comicId == null || comicId.isEmpty()) { throw new IllegalArgumentException("The ComicId must not be null or empty"); } ComicApiRest api = getApi(ComicApiRest.class); Call<MarvelResponse<ComicsDto>> call = api.getComic(comicId); MarvelResponse<ComicsDto> comics = execute(call); ComicsDto comicsDto = comics.getResponse(); if (comicsDto != null && comicsDto.getCount() > 0) { ComicDto comicDto = comicsDto.getComics().get(0); MarvelResponse<ComicDto> comicResponse = new MarvelResponse<>(comics); comicResponse.setResponse(comicDto); return comicResponse; } else { throw new MarvelApiException("Comic not found", null); } } ComicApiClient(MarvelApiConfig marvelApiConfig); MarvelResponse<ComicsDto> getAll(int offset, int limit); MarvelResponse<ComicsDto> getAll(ComicsQuery comicsQuery); MarvelResponse<ComicDto> getComic(String comicId);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptyComicIds() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); comicApiClient.getComic(INVALID_COMIC_ID); }
@Test public void shouldSendGetComicRequestToTheCorrectEndpoint() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse("getComic.json"); comicApiClient.getComic(ANY_COMIC_ID); assertRequestSentToContains("comics/" + ANY_COMIC_ID); }
@Test(expected = MarvelApiException.class) public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that comic\"}"); try { comicApiClient.getComic(ANY_NOT_FOUND_ID); } catch (MarvelApiException e) { assertEquals("404", e.getMarvelCode()); assertEquals("We couldn't find that comic", e.getMessage()); throw e; } }
@Test public void shouldParseGetComicResponse() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse("getComic.json"); MarvelResponse<ComicDto> comic = comicApiClient.getComic(ANY_COMIC_ID); assertBasicMarvelResponse(comic); ComicDto response = comic.getResponse(); assertIsLornaTheJungleGirl6(response); }