I have a test method testing admin privileges for a put method in my controller, which updates the my Route entity in a JPARepository. I added some logic to the controller to test if the update returns successfully by returning how many records were updated. It returns a 400 if the Integer returned is <1. Since I added that logic my unit test refuses to pass. I'm wondering what about the logic is making it so that it always returns a 400? Is my test written incorrectly?
The logic seems pretty staightforward. It's probably your expectation that your mock is returning 1 that's not lining up with the actual return value. If the value of noRecords on line 4 in your controller code is actually 0 then I'd look into how the mocks are getting set up. 0 is usually a default value so I'd look into why the thenReturn(new Integer(1)) isn't having the desired effect.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck