### Question:
ItemSearchResultConverter { public ItemSearchResult<I> toItemSearchResult() { return new ItemSearchResult<I>(page, nbResultsByPage, total, converter.convert(result.getResult())); } ItemSearchResultConverter(int page, int nbResultsByPage, SearchResult<E> result, ItemConverter<I, E> converter);  ItemSearchResultConverter(int page, int nbResultsByPage, SearchResult<E> result, long total, ItemConverter<I, E> converter); ItemSearchResult<I> toItemSearchResult();  }### Answer:
@Test public void testTotalCanBeRetrieved() { when(result.getCount()).thenReturn(5L); ItemSearchResultConverter<IItem, String> itemSearchResult = new ItemSearchResultConverter<IItem, String>(3, 2, result, converter); assertEquals(5L, itemSearchResult.toItemSearchResult().getTotal()); }
@Test public void testTotalSettedCanBeRetrieved() { ItemSearchResultConverter<IItem, String> itemSearchResult = new ItemSearchResultConverter<IItem, String>(3, 2, result, 8L, converter); assertEquals(8L, itemSearchResult.toItemSearchResult().getTotal()); }
@Test @Ignore("itemSearchResult return nbResultsByPage for length, need to be fixed in ItemSearchResult") public void testNumberOfResultCanBeRetrieved() { when(result.getResult()).thenReturn(asList("item1", "item2", "item3")); ItemSearchResultConverter<IItem, String> itemSearchResult = new ItemSearchResultConverter<IItem, String>(3, 10, result, 4L, converter); assertEquals(3, itemSearchResult.toItemSearchResult().getLength()); }
@Test(expected = APISearchIndexOutOfRange.class) public void testPageOutOfResultNumberThrowsExecption() throws Exception { when(result.getCount()).thenReturn(1L); new ItemSearchResultConverter<IItem, String>(2, 10, result, converter).toItemSearchResult(); }
@Test public void testPageNumberCanBeRetrieved() { ItemSearchResultConverter<IItem, String> itemSearchResult = new ItemSearchResultConverter<IItem, String>(5, 10, result, 8L, converter); assertEquals(5, itemSearchResult.toItemSearchResult().getPage()); }
@Test public void testResultingItemsCanBeRetrieved() { IItem item1 = mock(IItem.class); IItem item2 = mock(IItem.class); when(result.getResult()).thenReturn(asList("item1", "item2")); when(converter.convert(result.getResult())).thenReturn(asList(item1, item2)); ItemSearchResultConverter<IItem, String> itemSearchResult = new ItemSearchResultConverter<IItem, String>(1, 10, result, 2, converter); assertEquals(item1, itemSearchResult.toItemSearchResult().getResults().get(0)); assertEquals(item2, itemSearchResult.toItemSearchResult().getResults().get(1)); }