@Test public void canFindAccountByCredentialUsername() { Optional<Account> account = accountDAO.findAccountByUsername("admin"); assertThat(account.isPresent()).isTrue(); }
public Optional<Account> findAccountByUsername(String username) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_USERNAME, Account.class) .setParameter("username", username) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } else { return Optional.of(accounts.get(0)); } }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByUsername(String username) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_USERNAME, Account.class) .setParameter("username", username) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } else { return Optional.of(accounts.get(0)); } } }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByUsername(String username) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_USERNAME, Account.class) .setParameter("username", username) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } else { return Optional.of(accounts.get(0)); } } @SuppressWarnings("unused")  AccountDAO(); @VisibleForTesting  AccountDAO(EntityManager entityManager); }
AccountDAO extends AbstractDAO<Account> { public Optional<Account> findAccountByUsername(String username) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_USERNAME, Account.class) .setParameter("username", username) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } else { 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> findAccountByUsername(String username) { List<Account> accounts = getEntityManager() .createNamedQuery(Account.QUERY_BY_USERNAME, Account.class) .setParameter("username", username) .getResultList(); if (accounts.isEmpty()) { return Optional.empty(); } else { 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);  }