Refactor DAO and add test with mocks.