From the course: Test-Driven Development in Spring Boot with JUnit and Mockito

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Refactoring the first method of the controller

Refactoring the first method of the controller

- [Instructor] All right, let's refactor the controller a little. Looking at our code, there are two things that stand out to me. One, we used field injection here instead of constructor injection. Constructor injection is actually better for performance because it does not lean on the reflection API. So let's change that. And I don't need to add @Autowired to the controller because there's only one controller that's taken arguments here, so it's done by default. The other thing that stands out to me is that it's not returning the list directly here, but it's doing it in two steps, so let's change that two. Amazing. And after refactoring, what do we always do? Yes, that's right. We need to run our test again to make sure that it's still working as it should and that we did not change the external behavior. And it's passing, so that's great. Let's rinse and repeat, and add the rest of the controller in the next video.

Contents