### Question:
Newznab extends Indexer<Xml> { protected Xml getAndStoreResultToDatabase(URI uri, IndexerApiAccessType apiAccessType) throws IndexerAccessException { Xml response = getAndStoreResultToDatabase(uri, Xml.class, apiAccessType); if (response instanceof NewznabXmlError) { handleRssError((NewznabXmlError) response, uri.toString()); } else if (!(response instanceof NewznabXmlRoot)) { throw new UnknownResponseException("Indexer returned unknown response"); } return response; }  @Override NfoResult getNfo(String guid);  }### Answer:
@Test(expected = IndexerAuthException.class) public void shouldThrowAuthException() throws Exception { doReturn(new NewznabXmlError("101", "Wrong API key")).when(testee).getAndStoreResultToDatabase(any(), eq(Xml.class), eq(IndexerApiAccessType.SEARCH)); doNothing().when(testee).handleFailure(errorMessageCaptor.capture(), disabledPermanentlyCaptor.capture(), any(IndexerApiAccessType.class), any(), indexerApiAccessResultCaptor.capture()); testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100); }
@Test(expected = IndexerErrorCodeException.class) public void shouldThrowErrorCodeWhen100ApiHitLimits() throws Exception { doReturn(new NewznabXmlError("100", "Daily Hits Limit Reached\"")).when(testee).getAndStoreResultToDatabase(any(), eq(Xml.class), eq(IndexerApiAccessType.SEARCH)); doNothing().when(testee).handleFailure(errorMessageCaptor.capture(), disabledPermanentlyCaptor.capture(), any(IndexerApiAccessType.class), any(), indexerApiAccessResultCaptor.capture()); testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100); }
@Test(expected = IndexerProgramErrorException.class) public void shouldThrowProgramErrorCodeException() throws Exception { doReturn(new NewznabXmlError("200", "Whatever")).when(testee).getAndStoreResultToDatabase(any(), eq(Xml.class), eq(IndexerApiAccessType.SEARCH)); doNothing().when(testee).handleFailure(errorMessageCaptor.capture(), disabledPermanentlyCaptor.capture(), any(IndexerApiAccessType.class), any(), indexerApiAccessResultCaptor.capture()); testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100); }
@Test(expected = IndexerErrorCodeException.class) public void shouldThrowErrorCodeThatsNotMyFaultException() throws Exception { doReturn(new NewznabXmlError("123", "Whatever")).when(testee).getAndStoreResultToDatabase(any(), eq(Xml.class), eq(IndexerApiAccessType.SEARCH)); doNothing().when(testee).handleFailure(errorMessageCaptor.capture(), disabledPermanentlyCaptor.capture(), any(IndexerApiAccessType.class), any(), indexerApiAccessResultCaptor.capture()); testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100); }