@Test
  public void
      number_of_booking_during_time_period_returns_1_if_queried_with_end_date_in_the_middle_of_an_existing_booking() {
    LocalDate booking_from = LocalDate.of(2015, 7, 1);

    LocalDate booking_to = LocalDate.of(2015, 7, 18);

    LocalDate query_from = LocalDate.of(2015, 6, 12);
    LocalDate query_to = LocalDate.of(2015, 7, 12);

    Date from_date =
        Date.from(booking_from.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Date to_date = Date.from(booking_to.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Booking booking1 =
        Booking.builder()
            .apartment(apartment)
            .customer(customer)
            .startDate(from_date)
            .endDate(to_date)
            .build();

    repository.save(booking1);

    Date query_from_date =
        Date.from(query_from.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Date query_to_date =
        Date.from(query_to.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());

    assertThat(
        repository.findNumberOfBookingDuringTimePeriod(apartment, query_from_date, query_to_date),
        is(1));
  }
  @Test
  public void testInsert() {
    Booking b = new Booking();
    b.setApartment(apartment);
    b.setCustomer(customer);

    b = repository.save(b);

    assertEquals(b, repository.findOne(b.getId()));
  }
 public boolean canDeleteBooking(User user, long bookingId) {
   Booking booking = bookings.findOne(bookingId);
   return booking != null
       && ((booking.getGuest() != null && user.getUsername().equals(booking.getGuest().getEmail()))
           || (booking.getHotel() != null
               && booking.getHotel().getManager() != null
               && user.getUsername().equals(booking.getHotel().getManager().getEmail())));
 }
 public boolean canEditBooking(User user, long bookingId) {
   Booking booking = bookings.findOne(bookingId);
   return booking != null
       && booking.getGuest() != null
       && user.getUsername().equals(booking.getGuest().getEmail());
 }