From the course: Spring Cloud GCP: Setting Up a Cloud SQL Database
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Solution: Add tests for the GET endpoint
From the course: Spring Cloud GCP: Setting Up a Cloud SQL Database
Solution: Add tests for the GET endpoint
(upbeat music) - [Instructor] This video we'll go over the solution for this chapters challenge to add additional tests for the get endpoint. The first objective of this challenge was to add a unit test checking that the get endpoint returns a not found exception. In the test gets throws exception method. We need to configure our mock repository. We can again, use Mockito to do this and we want to say when the find by method on puzzle repository is called with any long ID, we want it to return an empty optional. Next, we want to obtain the HTTP client error exception. And we can use the assert throws method which needs a class name, the specific exception we are going to expect. And then a lambda calling the actual method on our controller with an arbitrary ID since we expect any ID to return an empty optional. We can now use the assert equals using HTTP status of not found and compare that with the error exceptions…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.