0

I have the following method to test in my Java service class:

public void findPersonToDelete(String id){

    //repository method then called
   personRepository.findPersonAndDelete(id);


}

The issue is that the personRepository calls other code which throws a Null Pointer.

I tried to use the following line to stop the personRepository from calling other methods:

  Mockito.doNothing().when(personRepository).findPersonAndDelete(id);

However the error is still persisting? How can I fix this?

java123999
  • 6,974
  • 36
  • 77
  • 121

1 Answers1

1

If you have a setter for your PersonRepository you can mock the class and set it in your service, this way the mocked class will be called and you can only check if it is called. so something like:

PersonRepository repo = Mockito.mock(PersonRepository.class);
service.setPersonRepository(repo);
service.findPersonToDelte(1);

and then check what you want to test.

LuckAss
  • 114
  • 7