private void addMockMaxUtilizations(Facility f, User apiUser) {
   final Integer capacity = f.builtCapacity.get(CAR);
   // Day 15 to ensure that weekdays stay in the same month
   final DateTime baseDate = BASE_DATE.toDateTimeAtCurrentTime().withDayOfMonth(15);
   facilityService.registerUtilization(
       f.id,
       asList(
           // 50/50 = 100%
           utilize(CAR, 0, baseDate.withDayOfWeek(MONDAY), f),
           // 25/50 =  50%
           utilize(CAR, capacity - (capacity / 2), baseDate.withDayOfWeek(SATURDAY), f),
           // 10/50 =  20%
           utilize(CAR, capacity - (capacity / 5), baseDate.withDayOfWeek(SUNDAY), f)),
       apiUser);
 }
  @Test
  public void whenADateFallsOnNonWorkingDayItShouldBeAdjustedToTheNearestWorkingDay() {

    DateTime firstOfNextMonth =
        new DateTime().plusMonths(1).withDayOfMonth(1).toDateMidnight().toDateTime();
    DateTime firstSaturdayOfNextMonth = firstOfNextMonth.withDayOfWeek(DayOfWeek.saturday());

    // exercise test
    DateTime adjustedDate = workingDayStrategy.adjust(firstSaturdayOfNextMonth);

    assertThat(adjustedDate, is(firstSaturdayOfNextMonth.plusDays(2)));
  }
  @Test
  public void whenADateFallsOnAWorkingDayItShouldNotBeAdjusted() {

    DateTime firstOfNextMonth =
        new DateTime().plusMonths(1).withDayOfMonth(1).toDateMidnight().toDateTime();
    DateTime firstTuesdayOfNextMonth = firstOfNextMonth.withDayOfWeek(DayOfWeek.tuesday());

    // exercise test
    DateTime adjustedDate = workingDayStrategy.adjust(firstTuesdayOfNextMonth);

    assertThat(adjustedDate, is(firstTuesdayOfNextMonth));
  }
 public WeeklyPeriod(Date date) {
   DateTime dt = new DateTime(date);
   startDate = dt.withDayOfWeek(DateTimeConstants.MONDAY).toDate();
   endDate = dt.withDayOfWeek(DateTimeConstants.SUNDAY).withTime(23, 59, 59, 999).toDate();
 }