@Test public void findOne() { Optional<User> actualOptional = userRepository.findOne(1L); if (!actualOptional.isPresent()) { fail("Return object is null"); } else { User actual = actualOptional.get(); assertEquals(EXPECTED_USER, actual); } }
@Override public Optional<User> findOne(Long id) { try { PreparedStatement statement = connection.prepareStatement(SQL_FIND_BY_ID); statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); User result = null; while (resultSet.next()) { result = rowMapper.rowMap(resultSet); } return Optional.ofNullable(result); } catch (SQLException e) { throw new IllegalArgumentException(e); } }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public Optional<User> findOne(Long id) { try { PreparedStatement statement = connection.prepareStatement(SQL_FIND_BY_ID); statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); User result = null; while (resultSet.next()) { result = rowMapper.rowMap(resultSet); } return Optional.ofNullable(result); } catch (SQLException e) { throw new IllegalArgumentException(e); } } }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public Optional<User> findOne(Long id) { try { PreparedStatement statement = connection.prepareStatement(SQL_FIND_BY_ID); statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); User result = null; while (resultSet.next()) { result = rowMapper.rowMap(resultSet); } return Optional.ofNullable(result); } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public Optional<User> findOne(Long id) { try { PreparedStatement statement = connection.prepareStatement(SQL_FIND_BY_ID); statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); User result = null; while (resultSet.next()) { result = rowMapper.rowMap(resultSet); } return Optional.ofNullable(result); } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll(); }
UsersRepositoryConnectionImpl implements UsersRepository { @Override public Optional<User> findOne(Long id) { try { PreparedStatement statement = connection.prepareStatement(SQL_FIND_BY_ID); statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); User result = null; while (resultSet.next()) { result = rowMapper.rowMap(resultSet); } return Optional.ofNullable(result); } catch (SQLException e) { throw new IllegalArgumentException(e); } } UsersRepositoryConnectionImpl(Connection connection); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll();  }