@Test public void shouldReturnNullWhenObjectNotFound() throws ErrorResultException { String tokenId = "badger"; DN testDN = DN.rootDN(); Connection mockConnection = mock(Connection.class); ErrorResultException exception = ErrorResultException.newErrorResult(ResultCode.NO_SUCH_OBJECT); given(mockConnection.readEntry(eq(testDN))).willThrow(exception); TokenAttributeConversion mockConversion = mock(TokenAttributeConversion.class); given(mockConversion.generateTokenDN(anyString())).willReturn(testDN); LDAPAdapter adapter = new LDAPAdapter(mockConversion); Token result = adapter.read(mockConnection, tokenId); assertThat(result).isNull(); }
public Token read(Connection connection, String tokenId) throws ErrorResultException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.readEntry(dn); return conversion.tokenFromEntry(resultEntry); } catch (ErrorResultException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw e; } }
LDAPAdapter { public Token read(Connection connection, String tokenId) throws ErrorResultException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.readEntry(dn); return conversion.tokenFromEntry(resultEntry); } catch (ErrorResultException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw e; } } }
LDAPAdapter { public Token read(Connection connection, String tokenId) throws ErrorResultException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.readEntry(dn); return conversion.tokenFromEntry(resultEntry); } catch (ErrorResultException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw e; } } @Inject  LDAPAdapter(TokenAttributeConversion conversion); }
LDAPAdapter { public Token read(Connection connection, String tokenId) throws ErrorResultException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.readEntry(dn); return conversion.tokenFromEntry(resultEntry); } catch (ErrorResultException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw e; } } @Inject  LDAPAdapter(TokenAttributeConversion conversion); 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); void deleteAsync(Connection connection, String tokenId, ResultHandler<Result> handler); }
LDAPAdapter { public Token read(Connection connection, String tokenId) throws ErrorResultException { DN dn = conversion.generateTokenDN(tokenId); try { SearchResultEntry resultEntry = connection.readEntry(dn); return conversion.tokenFromEntry(resultEntry); } catch (ErrorResultException e) { Result result = e.getResult(); if (result != null && ResultCode.NO_SUCH_OBJECT.equals(result.getResultCode())) { return null; } throw e; } } @Inject  LDAPAdapter(TokenAttributeConversion conversion); 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); void deleteAsync(Connection connection, String tokenId, ResultHandler<Result> handler);  }