I am trying to unit test a springboot application I inherited.
Here is how I initialise the mocking part of the unit test:
cReporistory cRepo;
Customer customer = new Customer();
customer.setUsername("foo");
// Other customer initialisations go here
cRepo = mock(cRepository.class);
when(cRepo.searchByUsername(any(String.class))).thenReturn(customer);
then in the production part, I have this line of code:
Customer customer = customerRepository.findByUsername(username);
I know that the correct values(username, password, id) is passed to the code, by checking the logs. The problem is that the line above is returning a NullPointerException.
Is this something obviously wrong? I would expect it to return a customer with username "foo", but it doesnt.
Aucun commentaire:
Enregistrer un commentaire