@Test public void canFindAccountByEmail() { Optional<Account> accountOpt = accountDAO.findAccountByEmail("admin@example.com"); assertThat(accountOpt.isPresent()).isTrue(); Account account = accountOpt.get(); assertThat(account.getId()).isNotNull(); assertThat(account.getName()).isEqualTo("John Smith"); }
public Optional<Account> findAccountByEmail(@Nonnull String email) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_EMAIL, Account.class) .setParameter("email", email) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } return Optional.of(accounts.get(0)); }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByEmail(@Nonnull String email) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_EMAIL, Account.class) .setParameter("email", email) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } return Optional.of(accounts.get(0)); } }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByEmail(@Nonnull String email) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_EMAIL, Account.class) .setParameter("email", email) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } return Optional.of(accounts.get(0)); } @SuppressWarnings("unused")  AccountDAO(); @VisibleForTesting  AccountDAO(EntityManager entityManager); }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByEmail(@Nonnull String email) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_EMAIL, Account.class) .setParameter("email", email) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } return Optional.of(accounts.get(0)); } @SuppressWarnings("unused")  AccountDAO(); @VisibleForTesting  AccountDAO(EntityManager entityManager); Optional<Account> findAccountByUsername(String username); List<Account> findAll(); List<Account> findAllEnabled(); Optional<Account> findAccountByEmail(@Nonnull String email); }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByEmail(@Nonnull String email) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_EMAIL, Account.class) .setParameter("email", email) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } return Optional.of(accounts.get(0)); } @SuppressWarnings("unused")  AccountDAO(); @VisibleForTesting  AccountDAO(EntityManager entityManager); Optional<Account> findAccountByUsername(String username); List<Account> findAll(); List<Account> findAllEnabled(); Optional<Account> findAccountByEmail(@Nonnull String email);  }