### Question:
LdapAdapter implements TokenStorageAdapter<Connection> { public void delete(Connection connection, String tokenId) throws LdapOperationFailedException { String dn = String.valueOf(conversion.generateTokenDN(tokenId)); try { processResult(connection.delete(LDAPRequests.newDeleteRequest(dn))); } catch (LdapException e) { Result result = e.getResult(); if (e.getResult() != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return; } throw new LdapOperationFailedException(e.getResult()); } } @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 shouldUseConnectionForDelete() throws Exception { String tokenId = "badger"; DN testDN = DN.rootDN(); Result successResult = mockSuccessfulResult(); given(mockConnection.delete(any(DeleteRequest.class))).willReturn(successResult); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); adapter.delete(mockConnection, tokenId); ArgumentCaptor<DeleteRequest> captor = ArgumentCaptor.forClass(DeleteRequest.class); verify(mockConnection).delete(captor.capture()); assertEquals(testDN, captor.getValue().getName()); }
@Test public void shouldDoNothingIfObjectNotFoundDuringDelete() throws Exception { String tokenId = "badger"; DN testDN = DN.rootDN(); LdapException exception = LdapException.newLdapException(ResultCode.NO_SUCH_OBJECT); given(mockConnection.delete(any(DeleteRequest.class))).willThrow(exception); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); adapter.delete(mockConnection, tokenId); }
@Test public void shouldThrowAllOtherExceptionsDuringDelete() throws Exception { String tokenId = "badger"; DN testDN = DN.rootDN(); LdapException exception = LdapException.newLdapException(ResultCode.OTHER); given(mockConnection.delete(any(DeleteRequest.class))).willThrow(exception); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); try { adapter.delete(mockConnection, tokenId); fail(); } catch (LdapOperationFailedException e) {} }