@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmptySeriesId() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); seriesApiClient.getSeriesById(INVALID_SERIES_ID); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenCallGetComicBySerieAndLimitIsZero() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getComicsBySeries(ANY_SERIE_ID, ANY_OFFSET, INVALID_LIMIT); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenCallGetComicBySerieAndSerieIdIsEmpty() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getComicsBySeries("", ANY_OFFSET, INVALID_LIMIT); }
@Test public void shouldSendOffsetAsLimitAsParamsWhenGetAll() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getAll(ANY_OFFSET, ANY_LIMIT); assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); }
@Test public void shouldSendGetSeriesRequestToTheCorrectEndpoint() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getSeriesCollection.json"); seriesApiClient.getSeriesById(ANY_SERIE_ID); assertRequestSentToContains("series/" + ANY_SERIE_ID); }
@Test public void shouldParseGetAllSeriesResponse() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getSeriesCollection.json"); MarvelResponse<SeriesCollectionDto> series = seriesApiClient.getAll(0, ANY_LIMIT); assertBasicMarvelResponse(series); assertGetAllSeriesResponseIsProperlyParsed(series); }
@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); }
@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(expected = MarvelAuthApiException.class) public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(401, "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " + "combination is invalid.\"}"); try { seriesApiClient.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; } }
@Test public void shouldUseAllTheRequestParamsAddedFromQueryWhenSendIt() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); SeriesQuery query = SeriesQuery.Builder.create() .withTitle(ANY_TITLE) .withTitleStartsWith(ANY_START_TITLE) .withStartYear(ANY_START_YEAR) .withLimit(ANY_LIMIT) .withOffset(ANY_OFFSET) .addCreator(ANY_CREATOR) .addCharacter(ANY_CHARACTER) .withModifiedSince(getAnyDate()) .withOrderBy(OrderBy.NAME, false) .addEvent(getAnyEvents()) .addComic(ANY_COMIC) .addStory(ANY_STORY) .withContains(Format.COMIC) .withSeriesType(SeriesQuery.SeriesType.COLLECTION) .build(); seriesApiClient.getAll(query); assertRequestSentToContains("startYear=" + ANY_START_YEAR, "creators=" + ANY_CREATOR, "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT, "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, "events=" + EVENTS_REQUEST, "comics=" + ANY_COMIC, "stories=" + ANY_STORY, "contains=" + Format.COMIC.toString(), "seriesType=" + SeriesQuery.SeriesType.COLLECTION.toString()); }
@Test public void shouldSendGetComicBySeriesRequestToTheCorrectEndpoint() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getComics.json");