### Question:
APICustomUserInfoUser extends ConsoleAPI<CustomUserInfoItem> implements APIHasSearch<CustomUserInfoItem> { @Override public ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters) { check(containsOnly(FILTER_USER_ID, filters), new _("The only mandatory filter is %name%", new Arg("name", FILTER_USER_ID))); check(orders.equals(FIX_ORDER), new _("Sorting is not supported by this API")); check(search == null, new _("Search terms are not supported by this API")); CustomUserInfoEngineClient client = engineClientCreator.create(getEngineSession()); List<CustomUserInfo> items = client.listCustomInformation( Long.parseLong(filters.get(FILTER_USER_ID)), page * resultsByPage, resultsByPage); List<CustomUserInfoItem> information = new ArrayList<CustomUserInfoItem>(); for (CustomUserInfo item : items) { information.add(converter.convert(item)); } return new ItemSearchResult<CustomUserInfoItem>(page, information.size(), client.countDefinitions(), information); } APICustomUserInfoUser(CustomUserInfoEngineClientCreator engineClientCreator); @Override ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters); @Override String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void should_retrieve_the_CustomUserInfo_for_a_given_user_id() throws Exception { given(engine.listCustomInformation(3L, 0, 2)).willReturn(Arrays.asList( new CustomUserInfo(3L, new EngineCustomUserInfoDefinition(5L), new CustomUserInfoValueImpl()), new CustomUserInfo(3L, new EngineCustomUserInfoDefinition(6L), new CustomUserInfoValueImpl()))); given(engine.countDefinitions()).willReturn(2L); List<CustomUserInfoItem> information = api.search(0, 2, null, "Fix order", Collections.singletonMap("userId", "3")).getResults(); assertThat(information.get(0).getDefinition().getId()).isEqualTo(APIID.makeAPIID(5L)); assertThat(information.get(1).getDefinition().getId()).isEqualTo(APIID.makeAPIID(6L)); }
@Test public void should_paginate_CustomUserInfo_search() throws Exception { given(engine.countDefinitions()).willReturn(2L); api.search(2, 2, null, "Fix order", Collections.singletonMap("userId", "3")).getResults(); verify(engine).listCustomInformation(3L, 4, 2); }
@Test(expected = APIException.class) public void should_fail_when_passing_an_order_to_the_search() { api.search(0, 2, null, "NAME ASC", Collections.singletonMap("userId", "3")).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_a_term_to_the_search() { api.search(0, 2, "foo", "Fix order", Collections.singletonMap("userId", "3")).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_a_no_filter_to_the_search() { api.search(0, 2, null, "Fix order", null).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_wrong_filter_to_the_search() { api.search(0, 2, null, "Fix order", Collections.singletonMap("foo", "bar")).getResults(); }