@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(expected = MarvelApiException.class) public void shouldReturnMarvelExceptionWhenTheIdDoesNotExist() throws Exception { CharacterApiClient characterApiClient = givenCharacterApiClient(); enqueueMockResponse(404, "{\"code\":404,\"status\":\"We couldn't find that character\"}"); try { characterApiClient.getCharacter(ANY_NOT_FOUND_ID); } catch (MarvelApiException e) { assertEquals("404", e.getMarvelCode()); assertEquals("We couldn't find that character", e.getMessage()); throw e; } }
@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 { 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; } }
@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(expected = MarvelAuthApiException.class) public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { CharacterApiClient characterApiClient = givenCharacterApiClient(); enqueueMockResponse(401, "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " + "combination is invalid.\"}"); try { characterApiClient.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; } }