@Test
  public void shouldNotCheckLimitationWhenIgnoreLimitationVariableIsTrue() {
    when(clinicDataService.findById(1l)).thenReturn(clinic);
    when(volunteerDataService.create(any(Volunteer.class))).thenReturn(new Volunteer());
    List<Screening> screenings =
        new ArrayList<>(
            Arrays.asList(
                createScreeningVisit(
                    2l, clinic, new LocalDate(2217, 1, 1), new Time(10, 0), new Time(11, 0)),
                createScreeningVisit(
                    3l, clinic, new LocalDate(2217, 1, 1), new Time(9, 0), new Time(10, 0))));

    when(screeningDataService.findByClinicIdAndDateAndStatus(
            1l, new LocalDate(2217, 1, 1), ScreeningStatus.ACTIVE))
        .thenReturn(screenings);

    ScreeningDto screeningDto = createScreeningDto("1", "1", "2217-1-1", "12:00");
    Screening screening = new Screening();
    screening.setId(1l);

    screeningService.add(screeningDto, true);

    verify(visitLimitationHelper, never())
        .checkCapacityForScreening(any(LocalDate.class), any(Clinic.class), anyLong());
    verify(screeningDataService, times(1)).create(any(Screening.class));
  }
  @Test
  public void shouldCheckCapacityLimitFirst() {
    when(clinicDataService.findById(1l)).thenReturn(clinic);
    when(volunteerDataService.create(any(Volunteer.class))).thenReturn(new Volunteer());
    List<Screening> screenings =
        new ArrayList<>(
            Arrays.asList(
                createScreeningVisit(
                    2l, clinic, new LocalDate(2217, 1, 1), new Time(10, 0), new Time(11, 0)),
                createScreeningVisit(
                    3l, clinic, new LocalDate(2217, 1, 1), new Time(9, 0), new Time(10, 0))));

    when(screeningDataService.findByClinicIdAndDateAndStatus(
            1l, new LocalDate(2217, 1, 1), ScreeningStatus.ACTIVE))
        .thenReturn(screenings);

    doThrow(
            new LimitationExceededException(
                "The clinic capacity limit for this day has been reached"))
        .when(visitLimitationHelper)
        .checkCapacityForScreening(any(LocalDate.class), any(Clinic.class), anyLong());

    ScreeningDto screeningDto = createScreeningDto("1", "1", "2217-1-1", "12:00");
    Screening screening = new Screening();
    screening.setId(1l);

    thrown.expect(LimitationExceededException.class);
    thrown.expectMessage("The clinic capacity limit for this day has been reached");
    screeningService.add(screeningDto, false);
  }
  @Test
  public void shouldThrowLimitationExceededExceptionWhenNumberOfRoomsLimitIsReached() {
    when(clinicDataService.findById(1l)).thenReturn(clinic);
    when(volunteerDataService.create(any(Volunteer.class))).thenReturn(new Volunteer());
    List<Screening> screenings =
        new ArrayList<>(
            Arrays.asList(
                createScreeningVisit(
                    2l, clinic, new LocalDate(2217, 1, 1), new Time(11, 0), new Time(12, 0))));

    when(screeningDataService.findByClinicIdAndDateAndStatus(
            1l, new LocalDate(2217, 1, 1), ScreeningStatus.ACTIVE))
        .thenReturn(screenings);

    ScreeningDto screeningDto = createScreeningDto("1", "1", "2217-1-1", "11:00");
    Screening screening = new Screening();
    screening.setId(1l);

    thrown.expect(LimitationExceededException.class);
    thrown.expectMessage("Too many visits at the same time");
    screeningService.add(screeningDto, false);
  }
  @Test
  public void shouldThrowLimitationExceededExceptionWhenTypeOfVisitLimitIsReached() {
    when(clinicDataService.findById(1l)).thenReturn(clinic);
    when(volunteerDataService.create(any(Volunteer.class))).thenReturn(new Volunteer());
    List<Screening> screenings =
        new ArrayList<>(
            Arrays.asList(
                createScreeningVisit(
                    2l, clinic, new LocalDate(2217, 1, 1), new Time(10, 0), new Time(11, 0)),
                createScreeningVisit(
                    3l, clinic, new LocalDate(2217, 1, 1), new Time(9, 0), new Time(10, 0))));

    when(screeningDataService.findByClinicIdAndDateAndStatus(
            1l, new LocalDate(2217, 1, 1), ScreeningStatus.ACTIVE))
        .thenReturn(screenings);

    ScreeningDto screeningDto = createScreeningDto("1", "1", "2217-1-1", "12:00");
    Screening screening = new Screening();
    screening.setId(1l);

    thrown.expect(LimitationExceededException.class);
    thrown.expectMessage("The booking limit for this type of visit has been reached");
    screeningService.add(screeningDto, false);
  }