From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Test Spring data repositories

Test Spring data repositories

- [Instructor] When developing an application, it's likely you'll need to save data in a database. Spring repositories provide an abstraction layer over data access. They simplify data access operations and reduce boilerplate code needed for performing common tasks such as create, read, update, and delete. Let's take a look at an example. This is a RESTful web service that handles users. There's a user controller with two endpoints, one for post where you can create a user, and the other is a get where you can retrieve a user. Both of these leverage the userService. Let's take a look. This class acts as a passthrough to the userRepository. The userRepository extends the Jpa interface provided by Spring Data JPA. This allows it to inherit several methods for working with user persistence, including methods for saving, deleting, and finding user entities. That's why in the Service class, we're able to use the find by id and save methods. Spring Data JPA is added to our application as a…

Contents