### Question:
LdapAdapter implements TokenStorageAdapter<Connection> { public Token read(Connection connection, String tokenId) throws DataLayerException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn)); return conversion.tokenFromEntry(resultEntry); } catch (LdapException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw new LdapOperationFailedException(result); } } @Inject  LdapAdapter(LdapTokenAttributeConversion conversion, LdapQueryFilterVisitor queryConverter,
            LdapQueryFactory queryFactory); void create(Connection connection, Token token); Token read(Connection connection,  String tokenId); boolean update(Connection connection, Token previous, Token updated); void delete(Connection connection, String tokenId); @Override Collection<Token> query(Connection connection, TokenFilter query); @Override Collection<PartialToken> partialQuery(Connection connection, TokenFilter query);  }### Answer:
@Test public void shouldUseConnectionForRead() throws Exception { String tokenId = "badger"; DN testDN = DN.rootDN(); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); adapter.read(mockConnection, tokenId); ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class); verify(mockConnection).searchSingleEntry(captor.capture()); assertEquals(testDN, captor.getValue().getName()); }
@Test public void shouldReturnNullWhenObjectNotFound() throws Exception { String tokenId = "badger"; DN testDN = DN.rootDN(); SearchRequest request = LDAPRequests.newSingleEntrySearchRequest(testDN); LdapException exception = LdapException.newLdapException(ResultCode.NO_SUCH_OBJECT); given(mockConnection.searchSingleEntry(request)).willThrow(exception); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); Token result = adapter.read(mockConnection, tokenId); assertThat(result).isNull(); }