Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

In this page you can find the example usage for java.time LocalDate now.

Prototype

public static LocalDate now(Clock clock) 

Source Link

Document

Obtains the current date from the specified clock.

Usage

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testGetAllReservations() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    assertTrue(reservationManager.findAllReservations().isEmpty());

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));

    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    List<Reservation> expected = Arrays.asList(r1, r2);
    List<Reservation> actual = reservationManager.findAllReservations();

    Collections.sort(actual, idComparator);
    Collections.sort(expected, idComparator);

    assertEquals("saved and retrieved reservations differ", expected, actual);
    assertDeepEquals(expected, actual);//from ww  w  . jav a  2s  . co  m
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestdeleteRoom() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));
    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    assertNotNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));

    reservationManager.deleteReservation(r1);

    assertNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestGetCostForReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Room room1 = setRoom(101, 2, 125, true);
    Room room2 = setRoom(102, 3, 250, false);
    roomManager.createRoom(room1);//  ww  w.j ava  2 s .  c  om
    roomManager.createRoom(room2);

    Guest guest1 = setGuest("Oleg Bezpalko", "Zagorska", "75899654", "Oleg999@mail");
    Guest guest2 = setGuest("Bogdan Voedylo", "Sobranetska", "78965452", "Myro777@mail");
    guestManager.createGuest(guest1);
    guestManager.createGuest(guest2);

    Reservation r1 = setReservation(room1.getId(), guest1.getId(), checkin, checkout, reservationdate);
    Reservation r2 = setReservation(room2.getId(), guest2.getId(), checkin.plusDays(1), checkout.plusDays(2),
            reservationdate);

    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    assertThat("reservation 1 resturns wrong total price",
            reservationManager.getCoastForReservation(r1.getGuestId()), is(equalTo(5 * 125)));
    assertThat("reservation 2 returns wrong total price",
            reservationManager.getCoastForReservation(r2.getGuestId()), is(equalTo(6 * 250)));
    assertThat("with no reservation price differs from 0", reservationManager.getCoastForReservation(3L),
            is(equalTo(0)));
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestAssignRoomToGuest() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Room room1 = setRoom(101, 2, 125, true);
    roomManager.createRoom(room1);//from  w  ww .j a v a 2  s.c om

    Guest guest1 = setGuest("Oleg Bezpalko", "Zagorska", "75899654", "Oleg999@mail");
    guestManager.createGuest(guest1);

    reservationManager.assignRoomToGuest(guest1, room1, checkin, checkout);
    List<Reservation> reservation = reservationManager.findAllReservations();

    assertThat("wrong size or reservations created", reservation.size(), is(equalTo(1)));

    assertThat("room id was changed", reservation.get(0).getRoomId(), is(equalTo(room1.getId())));
    assertThat("guest id was changed", reservation.get(0).getGuestId(), is(equalTo(guest1.getId())));
    assertThat("resrvation date was changed", reservation.get(0).getReservationDate(),
            is(equalTo(reservationdate)));
    assertThat("checkin date was changed", reservation.get(0).getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation.get(0).getCheckoutDate(), is(equalTo(checkout)));
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestFindFreeRoomsforReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);

    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Room room1 = setRoom(101, 2, 125, true);
    Room room2 = setRoom(102, 3, 255, false);
    Room room3 = setRoom(103, 2, 129, true);
    Room room4 = setRoom(104, 3, 254, false);
    Room room5 = setRoom(105, 2, 1278, true);
    Room room6 = setRoom(106, 3, 252, false);
    roomManager.createRoom(room1);//from w  ww.  j  a  v a2  s . co m
    roomManager.createRoom(room2);
    roomManager.createRoom(room3);
    roomManager.createRoom(room4);
    roomManager.createRoom(room5);
    roomManager.createRoom(room6);

    Guest guest1 = setGuest("Oleg Bezpalko", "Zagorska", "75899654", "Oleg999@mail");
    Guest guest2 = setGuest("Bogdan Voedylo", "Sobranetska", "78965452", "Bogadan777@mail");
    Guest guest3 = setGuest("Vasya Voedylo", "Mynaiska", "789999992", "Vasya777@mail");
    guestManager.createGuest(guest3);
    guestManager.createGuest(guest1);
    guestManager.createGuest(guest2);

    reservationManager.assignRoomToGuest(guest1, room4, checkin, checkout);
    reservationManager.assignRoomToGuest(guest2, room6, checkin.plusDays(3), checkout.plusDays(5));
    reservationManager.assignRoomToGuest(guest3, room1, checkin.minusDays(5), checkout.minusDays(3));

    List<Room> freerooms1 = reservationManager.findFreeRoomsforReservation(checkin, checkout);
    assertThat("wrong size or rooms created", freerooms1.size(), is(equalTo(3)));

    List<Room> freerooms2 = reservationManager.findFreeRoomsforReservation(checkin.plusDays(2),
            checkout.minusDays(2));
    assertThat("wrong size or rooms created", freerooms2.size(), is(equalTo(5)));

    List<Room> freerooms3 = reservationManager.findFreeRoomsforReservation(checkin, checkin);
    assertThat("wrong size or rooms created", freerooms3.size(), is(equalTo(4)));
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void TestFindRoomWithGuest() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Room room1 = setRoom(101, 2, 125, true);
    Room room2 = setRoom(102, 3, 250, false);
    roomManager.createRoom(room1);/*from  w w  w.j av  a2s . c om*/
    roomManager.createRoom(room2);

    Guest guest1 = setGuest("Oleg Bezpalko", "Zagorska", "75899654", "Oleg999@mail");
    Guest guest2 = setGuest("Bogdan Voedylo", "Sobranetska", "78965452", "Myro777@mail");
    guestManager.createGuest(guest1);
    guestManager.createGuest(guest2);

    reservationManager.assignRoomToGuest(guest1, room2, checkin, checkout);
    reservationManager.assignRoomToGuest(guest2, room1, checkin, checkout);

    List<Room> roomf1 = reservationManager.findRoomWithGuest(guest2);
    assertThat("wrong size or rooms found", roomf1.size(), is(equalTo(1)));
    assertDeepEquals(roomf1.get(0), room1);

    List<Room> roomf2 = reservationManager.findRoomWithGuest(guest1);
    assertThat("wrong size or rooms found", roomf2.size(), is(equalTo(1)));
    assertDeepEquals(roomf2.get(0), room2);

    Room room3 = setRoom(103, 3, 250, false);
    roomManager.createRoom(room3);
    reservationManager.assignRoomToGuest(guest1, room3, checkin, checkout);

    List<Room> roomf3 = reservationManager.findRoomWithGuest(guest1);
    assertThat("wrong size or rooms found", roomf3.size(), is(equalTo(2)));
}

From source file:nu.yona.server.analysis.service.ActivityServiceTest.java

@Test
public void getUserDayActivityDetail_noActivityPresent_resultWithInactivity() {
    ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone));

    DayActivityDto inactivityDay = service.getUserDayActivityDetail(userId, LocalDate.now(userAnonZone),
            gamblingGoal.getId());/*from   w ww.  jav  a  2  s.co  m*/

    assertThat(inactivityDay.getSpread().size(), equalTo(96));
    assertThat(inactivityDay.getStartTime(), equalTo(today));
    assertThat(inactivityDay.getTimeZoneId(), equalTo(userAnonZone.getId()));
    assertThat(inactivityDay.getTotalActivityDurationMinutes().get(), equalTo(0));
    assertThat(inactivityDay.getTotalMinutesBeyondGoal(), equalTo(0));
}

From source file:nu.yona.server.analysis.service.ActivityServiceTest.java

@Test
public void getUserWeekActivityDetail_noActivityPresent_resultWithInactivity() {
    WeekActivityDto inactivityWeek = service.getUserWeekActivityDetail(userId,
            getWeekStartDate(LocalDate.now(userAnonZone)), gamblingGoal.getId());

    assertThat(inactivityWeek.getSpread().size(), equalTo(96));
    assertThat(inactivityWeek.getStartTime(), equalTo(getWeekStartTime(ZonedDateTime.now(userAnonZone))));
    assertThat(inactivityWeek.getTimeZoneId(), equalTo(userAnonZone.getId()));
    assertThat(inactivityWeek.getTotalActivityDurationMinutes().get(), equalTo(0));
}

From source file:nu.yona.server.analysis.service.ActivityService.java

private LocalDate getCurrentDayDate(UserAnonymizedDto userAnonymized) {
    return LocalDate.now(userAnonymized.getTimeZone());
}