### Question:
APICustomUserInfoDefinition extends ConsoleAPI<CustomUserInfoDefinitionItem> implements
        APIHasAdd<CustomUserInfoDefinitionItem>,
        APIHasSearch<CustomUserInfoDefinitionItem>,
        APIHasDelete { public ItemSearchResult<CustomUserInfoDefinitionItem> search( final int page, final int resultsByPage, final String search, final String orders, final Map<String, String> filters) { check(search == null, new _("Search terms are not supported by this API")); check(filters == null || filters.isEmpty(), new _("Filters are not supported by this API")); check(orders.equals(FIX_ORDER), new _("Sorting is not supported by this API")); CustomUserInfoEngineClient client = engineClientCreator.create(getEngineSession()); List<CustomUserInfoDefinitionItem> result = new ArrayList<CustomUserInfoDefinitionItem>(); for (CustomUserInfoDefinition definition : client.listDefinitions(page * resultsByPage, resultsByPage)) { result.add(converter.convert(definition)); } return new ItemSearchResult<CustomUserInfoDefinitionItem>(page, resultsByPage, client.countDefinitions(), result); } APICustomUserInfoDefinition(CustomUserInfoEngineClientCreator engineClientCreator); CustomUserInfoDefinitionItem add(CustomUserInfoDefinitionItem definition); void delete(final List<APIID> ids); ItemSearchResult<CustomUserInfoDefinitionItem> search(
            final int page,
            final int resultsByPage,
            final String search,
            final String orders,
            final Map<String, String> filters); String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void search_should_retrieve_the_list_of_item_from_the_specified_range() throws Exception { given(engine.listDefinitions(4, 2)).willReturn(Arrays.<CustomUserInfoDefinition> asList( new EngineCustomUserInfoDefinition(3L), new EngineCustomUserInfoDefinition(4L))); given(engine.countDefinitions()).willReturn(6L); List<CustomUserInfoDefinitionItem> result = api.search(2, 2, null, APICustomUserInfoDefinition.FIX_ORDER, null).getResults(); assertThat(result.get(0).getId()).isEqualTo(APIID.makeAPIID(3L)); assertThat(result.get(1).getId()).isEqualTo(APIID.makeAPIID(4L)); }
@Test public void search_should_retrieve_the_total_number_of_definitions() throws Exception { given(engine.countDefinitions()).willReturn(42L); ItemSearchResult<CustomUserInfoDefinitionItem> result = api.search(0, 2, null, APICustomUserInfoDefinition.FIX_ORDER, null); assertThat(result.getTotal()).isEqualTo(42); }
@Test public void should_allow_an_empty_filter() throws Exception { given(engine.countDefinitions()).willReturn(42L); ItemSearchResult<CustomUserInfoDefinitionItem> result = api.search(0, 2, null, APICustomUserInfoDefinition.FIX_ORDER, Collections.<String, String> emptyMap()); assertThat(result.getTotal()).isEqualTo(42); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_filters_are_passed_through() throws Exception { api.search(0, 1, null, APICustomUserInfoDefinition.FIX_ORDER, Collections.singletonMap("name", "foo")); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_an_order_is_passed_through() throws Exception { api.search(0, 1, null, "NAME ASC", null); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_a_search_is_passed_through() throws Exception { api.search(0, 1, "foo", APICustomUserInfoDefinition.FIX_ORDER, null); }