### Question:
ApacheAPIConverter { SearchRequest toSearchRequest(QueryRequest queryRequest, String baseSearchPath) throws LdapException { SearchRequest search = new SearchRequestImpl(); search.setScope(SearchScope.SUBTREE); String[] translatedRequestedFieldsArray = toStringArray(queryRequest.getRequestedFields()); search.addAttributes(translatedRequestedFieldsArray); search.setTimeLimit(queryRequest.getTimeLimit()); search.setSizeLimit(queryRequest.getSizeLimit()); search.setBase(new Dn(baseSearchPath)); if (queryRequest.getReferralsHandling() == ReferralsHandling.FOLLOW) { search.followReferrals(); } else if (queryRequest.getReferralsHandling() == ReferralsHandling.IGNORE) { search.ignoreReferrals(); } String searchText = queryRequest.getSearchText() == null ? queryRequest.getSearchSentenceText() : queryRequest.getSearchText(); if (searchText != null && !searchText.trim().isEmpty()) search.setFilter(searchText); List<SortKey> sortKeys = queryRequest.getSortKeys(); if (!Objects.isNull(sortKeys) && !sortKeys.isEmpty()) { SortRequestControlImpl sortRequest = applySort(sortKeys); search.addControl(sortRequest); } return search; }  Modification toModification(ModificationDetails modificationDetails);  }### Answer:
@Test public void testToApacheSearchRequest() throws LdapException { QueryRequest search = mock(QueryRequest.class); Endpoint endpoint = mock(Endpoint.class); when(search.getTimeLimit()).thenReturn(1000); when(search.getSizeLimit()).thenReturn(1000); when(search.getSearchText()).thenReturn("(l=LTV)"); when(search.getReferralsHandling()).thenReturn(ReferralsHandling.FOLLOW); when(search.getRequestedFields()).thenReturn(null); SearchRequest searchRequest = new ApacheAPIConverter().toSearchRequest(search, endpoint.getBaseSearchPath()); assertTrue(searchRequest.getSizeLimit() == search.getSizeLimit()); assertTrue(searchRequest.getTimeLimit() == search.getTimeLimit()); assertTrue(searchRequest.getFilter().toString().equals(search.getSearchText())); assertTrue(searchRequest.isFollowReferrals()); }
@Test public void testToApacheSearchRequestPaged() throws LdapException { QueryRequest search = mock(QueryRequest.class); Endpoint endpoint = mock(Endpoint.class); when(search.getPageChunkSize()).thenReturn(1000); when(search.getTimeLimit()).thenReturn(1000); when(search.getSizeLimit()).thenReturn(1000); when(search.getSearchText()).thenReturn("(l=LTV)"); when(search.getReferralsHandling()).thenReturn(ReferralsHandling.FOLLOW); when(search.isPaged()).thenReturn(true); when(search.getRequestedFields()).thenReturn(null); byte[] cookie = new byte[1]; SearchRequest searchRequest = new ApacheAPIConverter().toSearchRequest(search, endpoint.getBaseSearchPath(), endpoint.getCookie()); assertTrue(searchRequest.getControls().values().toArray()[0] instanceof PagedResults); assertTrue(((PagedResults) searchRequest.getControls().values().toArray()[0]).getSize() == search.getPageChunkSize()); }