I'm trying to test a service class (responsible for calling the repository layer and do some operations if needed), basically, this is the class I'm trying to test
class CarServiceImpl{
public Car findById(String id){
//call repository layer to find a car
}
public void deleteById(String id){
Car car = this.findById(id);
if(car != null){
//Call repository layer to update the car
}else{
Throw NotFOundException();
}
}
}
As you can see I call the findById method on the deleteById method, so my questions are.
is it really code smell to call a method on the same class? I don think I should create a separate class to find a car by id.
how can I mock the call to "findById" on the "deleteById" method, if I use
Mockito.when(carServiceImpl.findById("car1")).thenReturn(carModel);it stills call the method so i'll need to mock the call to respository for finding by id too, even when i already tested the method findById.