I am currently working on Web project using Hibernate/Spring for the persistence layer. I decided to use the not the old DTO/DAO. That means the data is encapsulated in POJO’s, the Data Transfer Objects (DTO’s), and Data Access Objects (DAO’s) are used to actually access the database. Typical methods from DAO’s are getXXXById, create, … Ok, so far so good. The next thing I wanted to do, is to use the DAO’s in other objects, let’s call them Commands. Such a command gets some information, makes some checks, and does something. Some of them are checking if an entity already exisits, e.g. if an entity with the same username already exists. Not really a problem until now, but I also want to test the commands, therfore, I need some mocks. In this case I need DAO mocks. So the DAO’s have to be interchangeable while the Commands are created with “new”. Further, I wanted them injected before the constructor runs.
