CustomerDAO { public int getNextId() throws SQLException { if (LOG.isTraceEnabled()) { LOG.trace("CustomerDAO.getNextId()"); } int id = 1; final Connection connection = getConnection(); final PreparedStatement statement = connection.prepareStatement("SELECT id FROM customer ORDER BY id DESC LIMIT 1;"); final ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { id = resultSet.getInt("id") + 1; } connection.close(); return id; } 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 testGetNextIdWithEmptyDatabase() throws SQLException { Assert.assertEquals(1, customerDAO.getNextId()); }