RestaurantControllerTest stub is mocking different method but verifying another one

As seen here

findAllRestaurantsCloseBy is mocked but findRestaurantsBySearchQuery is checked

I am not understanding how to make this case pass ,

  1. Assuming the RestaurantController logic only calls the findAllRestaurantsCloseBy irrespective of searchQuery being present or not , and redirecting to findRestaurantsBySearchQuery if searchQuery is present , then check on 161 would fail as we are mocking the call and call to findRestaurantsBySearchQuery will never happen

  2. If I put a condition in RestaurantController for searchQuery being empty or not and call
    i ) findAllRestaurantsCloseBy if searchQuery is empty or
    ii ) findRestaurantsBySearchQuery if searchQuery present
    In this case as mock is done only for findAllRestaurantsCloseBy , the test would fail with null pointer

I am stuck here

Hi @vikhyatprabhu,
Good catch. The thing is that mock has no value. If you see we aren’t doing any assertions on the output we are getting response. Only assertions are on the ArgumentCaptor output.

Your proposal (2) would be the right-way to go. And you’re right, as we’re mocking the service layer, the output from service layer will be null. You can do checks for that to not cause a NullPointerException

Will update the stubs ASAP, feel free to comment out the stubbing part - when().thenReturn()

I can push by commenting out , but you would need to update the stubs for the assessment to pass right?

No, it shouldn’t. As I mentioned, the stubbing is actually not relevant here as we’re not making any assertions on the response returned from service layer.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.