Relative Content

Tag Archive for javaspring

Loose Coupling in Spring and Role of DI

I’m new to Spring and currently learning it through some paid courses. I came across the concept of loose coupling, and I understand that Spring promotes defining behavior in interfaces. However, I am wondering why it’s necessary to define behavior in an interface instead of directly extending the implementation in a class?

How do I mock a list in unit test?

I’m developing an API using Java Spring. It has a controller, a service and a repository, in the repository I deserialize a JSON file and populate a list. I want to create unit tests for the repository. How do I mock this list, so I don’t change it during testing? I’m having doubts regarding the concept of unit tests, should this list be mocked or can I use the list that is used in the repository?