Skip to content
Advertisement

Testing a Spring ControllerMethod using Mockito which alters an entry in the db with Optional.map NullPOinterException

Im currently Testing my Controller methods. In one Method I add a Reisepunkt(travelpoint) to a Reise(travel), which is already saved inside a database.

JavaScript

Using the generated-request.http API I can use the method to make entrys into the db. Now i wanted to write a test method just so I can get the hang of it.

JavaScript

I always get a NullPointerException in the lines:

JavaScript

Apperently Mockito has a problem when I map an Optional inside another Optional.map and then use given for the second Repository request. I guess there is some special way to implement the Test methode for a given Repo request inside a Optional map.

Advertisement

Answer

You forgot to mock ReisepunktRepository and this cause the NullPointerException

Update from

JavaScript

To

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement