I use DAO interfaces, so that I can implement both a real DAO and a test DAO. For example, this is the interface:
public interface PersonDAO {
public List<Person> findAll();
}
Then I ll have 2 implementations of this interface:
public class PersonHibernateDAO implements PersonDAO {
public List<Person> findAll() {
// use Hibernate to find and return all the Person objects
}
}
public class PersonTestDAO implements PersonDAO {
public List<Person> findAll() {
List<Person> testData = new ArrayList<Person>();
testData.add(new Person("Bob");
testData.add(new Person("Steve");
return testData;
}
}
The controller itself uses a PersonDAO, and you can supply either the Hibernate implementation (when in production or testing against the database), or the Test implementation (when unit testing or playing around before the database is set up).