/** Test of finding rooms by hotel */ @Test public void findByHotelTest() { List<Room> list = new ArrayList<>(); list.add(room1); Hotel hotel = new Hotel(); when(roomDao.findByHotel(any(Long.class))).thenReturn(list); assertEquals((roomService.findByHotel(hotel.getId())).size(), 1); verify(roomDao).findByHotel(any(Long.class)); }
/** Prepare example objects */ @Before public void createRoom() { MockitoAnnotations.initMocks(this); room1 = new Room(); room2 = new Room(); room3 = new Room(); room1.setId((long) 1); room1.setName("57"); room1.setNumberOfBeds(3); room1.setPrice(new BigDecimal("80.00")); room1.setHotel(hotel1); room2.setId((long) 2); room2.setName("120"); room2.setNumberOfBeds(1); room2.setPrice(new BigDecimal("150.00")); room2.setHotel(hotel2); room3.setId((long) 3); room3.setName("58"); room3.setNumberOfBeds(3); room3.setPrice(new BigDecimal("80.00")); hotel1 = new Hotel(); hotel2 = new Hotel(); hotel1.setName("Hotel 1"); hotel1.setAddress("Hotel address 1"); hotel2.setName("Hotel 2"); hotel2.setAddress("Hotel address 2"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); nextMonthFirstDay = calendar.getTime(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); nextMonthLastDay = calendar.getTime(); reservation1 = new Reservation(); reservation2 = new Reservation(); reservation1.setStartOfReservation(nextMonthFirstDay); reservation1.setEndOfReservation(nextMonthLastDay); reservation1.setRoom(room1); reservation2.setStartOfReservation(nextMonthFirstDay); reservation2.setEndOfReservation(nextMonthLastDay); reservation2.setRoom(room2); }