If you have Spring controller that uses repository objects, it can become a bit messy to write tests with mocks that have to mock various repository object methods like save() etc. Instead, you can use Here is an example controller that uses repository objects: @RestController public class StateManagerController { public StateManagerController(XRepository aRepository, YRespository yRepo) { } public void aMethod() { // use xRepo, yRepo : e.g., xRepo.save() , yRepo.delete() etc. } ... } To test methods of this controller that use the repository objects, you will likely have to mock each repository collaborator object. Then you can get into lots of mocking details that make your tests ugly. Instead, I find that using the following pattern greatly simplifies both your code and tests. It's very simple but works great. 1. In your controller, only inject/depend on @Service objects. Don't use repository objects directly 2. Test your con...
I want to learn something new every day, but can I?