CustomerDAO { public void update(final Customer customer) throws SQLException, DuplicateException { if (LOG.isTraceEnabled()) { LOG.trace("CustomerDAO.update(customer=" + customer + ")"); } final Customer currentCustomer = get(customer.getId()); if (isDuplicateName(customer) && !currentCustomer.equals(customer)) { throw new DuplicateException("Customers with duplicate names are not allowed. Customer: " + customer); } final Connection connection = getConnection(); final PreparedStatement statement = connection.prepareStatement("UPDATE customer SET name = '" + customer.getName() + "' WHERE id = '" + customer.getId() + "';"); statement.executeUpdate(); connection.close(); } CustomerDAO(final String dataSourceJndi); int getNextId(); Customer get(final int id); List<Customer> getAll(); void insert(final Customer customer); void update(final Customer customer); void delete(final Customer customer); void clear();  }
@Test public void testUpdate() throws SQLException, DuplicateException { final Customer customer1 = new Customer(1, "First customer name"); final Customer customer2 = new Customer(1, "Second customer name"); customerDAO.insert(customer1); customerDAO.update(customer2); Assert.assertEquals(customer2, customerDAO.get(1)); }