Service 如何使用模拟dao测试服务方法并避免NPE

Service 如何使用模拟dao测试服务方法并避免NPE,service,null,mockito,Service,Null,Mockito,Mockito中的新手,尝试测试方法: public boolean isPlaceBookedForDate(Long id, LocalDate date) { Place place; Boolean res; try { place = this.repository.getById( id ); res = place.getCalendar() .i

Mockito中的新手,尝试测试方法:

public boolean isPlaceBookedForDate(Long id, LocalDate date) {
        Place place;
        Boolean res;
        try {
            place = this.repository.getById( id );
            res = place.getCalendar()
                    .isDateBooked( date );
        } catch (Exception e) {
            log.error( "failed to find place by id! " + e );
            throw new RuntimeException();
          
        }
        return res;
    }
由于Mocked repo返回null并试图调用方法getCalendar(),因此NPE将失败。 有没有办法测试和避免它