In (most)JS and/or python I would just monkey patch the save method and/or constructor on the employee object to get the isolation and branch coverage.
I would probably need to do some of the same crazy abstraction for Java though.
In (most)JS and/or python I would just monkey patch the save method and/or constructor on the employee object to get the isolation and branch coverage.
I would probably need to do some of the same crazy abstraction for Java though.
public Employee create() { ... mapper.save(employee); return employee; }
Done.
All you do now is create a mock employee mapper in your tests, and you can verify just what you want in the Controller instead of anything else
You've got * Single responsibility classes (Controller manages employee creation business logic; Mapper is a dumb database wrapper; If you want to go even further, use a Repository instead of a Mapper to introduce one more layer of abstraction between the data model, that way you can slide in caching or in-memory replacements, or what have you at will) * Clean dependencies. There's nothing hidden about what this class needs to get it's work done