### Question:
QueryRequestNonPagedExecutor extends QueryRequestExecutor { RoundtripResult collectData(LdapConnection connection, SearchRequest search) { RoundtripResult roundtripResult = new RoundtripResult(); SearchCursor cursor = null; List<Entry> result = new ArrayList<>(); try { cursor = connection.search(search); result = this.run(cursor); roundtripResult.setData(result); } catch (LdapException e) { LOGGER.error("Can't execute non-paged LDAP query", e.getStackTrace()); } finally { if (cursor != null) { try { cursor.close(); } catch (IOException e) { LOGGER.error("Can't close cursor", e.getStackTrace()); } } } LOGGER.trace("Collect Data. Data size:", result == null ? "NaN" : result.size()); return roundtripResult; } QueryRequestNonPagedExecutor(QueryRequest queryRequest);   }### Answer:
@Test public void testCollectData() { try { when(ldapConnection.search(any(SearchRequest.class))).thenReturn(mock(SearchCursor.class)); doReturn(null).when(queryRequestNonPagedExecutor).run(any(SearchCursor.class)); RoundtripResult roundtripResult = queryRequestNonPagedExecutor.collectData(ldapConnection, mock(SearchRequest.class)); assertNotNull(roundtripResult); } catch (LdapException e) { e.printStackTrace(); } }
@Test public void testCollectDataFailed() { try { LdapException ldapException = mock(LdapException.class); SearchRequest searchRequest = new SearchRequestImpl(); doThrow(ldapException).when(ldapConnection).search(searchRequest); queryRequestNonPagedExecutor.collectData(ldapConnection, searchRequest); verify(ldapException, times(1)).getStackTrace(); } catch (LdapException e) { e.printStackTrace(); } }