public MarvelResponse<ComicsDto> getAll(int offset, int limit) throws MarvelApiException { ComicsQuery query = ComicsQuery.Builder.create().withOffset(offset).withLimit(limit).build(); return getAll(query); }
} else if (operation.equals("getComics")) { ComicApiClient comicApiClient = new ComicApiClient(marvelApiConfig); MarvelResponse<ComicsDto> comics = comicApiClient.getAll(0, 10); System.out.println(comics.toString()); } else if (operation.equals("getComic")) {
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(); comicApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); }
@Test public void shouldRequestComicsByOffsetAndLimitWithAsParams() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(); comicApiClient.getAll(ANY_OFFSET, ANY_LIMIT); assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); }
@Test public void shouldParseGetAllComicsResponse() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse("getComics.json"); MarvelResponse<ComicsDto> comics = comicApiClient.getAll(0, ANY_LIMIT); assertBasicMarvelResponse(comics); assertGetAllComicsResponseIsProperlyParsed(comics); }
@Test(expected = MarvelAuthApiException.class) public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(401, "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " + "combination is invalid.\"}"); try { comicApiClient.getAll(ANY_OFFSET, ANY_LIMIT); } catch (MarvelApiException e) { assertEquals("InvalidCredentials", e.getMarvelCode()); assertEquals("That hash, timestamp and key combination is invalid.", e.getMessage()); throw e; } }
.build(); comicApiClient.getAll(query);