### Question:
LdapQueryBuilder extends QueryBuilder<Connection, Filter> { @Override public String toString() { return MessageFormat.format( "Query:\n" + " Filter: {0}\n" + " Attributes: {1}", getLDAPFilter(), StringUtils.join(requestedAttributes, ", ")); } @Inject  LdapQueryBuilder(LdapDataLayerConfiguration dataLayerConfiguration, LdapSearchHandler handler,
            @Named(DataLayerConstants.DATA_LAYER_DEBUG) Debug debug,
            Map<Class, EntryConverter> converterMap); Iterator<Collection<T>> executeRawResults(Connection connection, Class<T> returnType); @Override String toString(); static final ByteString EMPTY; }### Answer:
@Test public void shouldReturnTokensFromSearch() throws CoreTokenException { final Collection<Entry> entries = new LinkedList<Entry>(); entries.add(new LinkedHashMapEntry()); entries.add(new LinkedHashMapEntry()); given(searchHandler.performSearch(any(Connection.class), any(SearchRequest.class), any(Collection.class))).will(new Answer() { public Object answer(InvocationOnMock invocationOnMock) throws Throwable { Collection<Entry> list = (Collection<Entry>) invocationOnMock.getArguments()[2]; list.addAll(entries); return null; } }); given(tokenEntryConverter.convert(any(Entry.class), any(String[].class))).willReturn( new Token(Long.toString(currentTimeMillis()), TokenType.SESSION)); Iterator<Collection<Token>> results = builder.execute(mockConnection); verifyZeroInteractions(tokenEntryConverter); assertThat(results.next().size()).isEqualTo(entries.size()); verify(tokenEntryConverter, times(2)).convert(any(Entry.class), any(String[].class)); }
@Test public void shouldReturnTokensFromSearch() throws CoreTokenException { final Collection<Entry> entries = new LinkedList<Entry>(); entries.add(new LinkedHashMapEntry()); entries.add(new LinkedHashMapEntry()); given(searchHandler.performSearch(any(Connection.class), any(SearchRequest.class), any(Collection.class))).will(new Answer() { public Object answer(InvocationOnMock invocationOnMock) throws Throwable { Collection<Entry> list = (Collection<Entry>) invocationOnMock.getArguments()[2]; list.addAll(entries); return null; } }); given(tokenEntryConverter.convert(any(Entry.class), any(String[].class))).willReturn( new Token(Long.toString(System.currentTimeMillis()), TokenType.SESSION)); Iterator<Collection<Token>> results = builder.execute(mockConnection); verifyZeroInteractions(tokenEntryConverter); assertThat(results.next().size()).isEqualTo(entries.size()); verify(tokenEntryConverter, times(2)).convert(any(Entry.class), any(String[].class)); }