/** 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); }
/** Test of changing price of room */ @Test public void changeRoomPriceTest() { BigDecimal price = new BigDecimal("99.0"); doAnswer( invocationOnMock -> { room1.setPrice(price); return null; }) .when(roomDao) .update(any(Room.class)); assertNotEquals(room1.getPrice(), price); roomService.changeRoomPrice(room1, price); verify(roomDao).update(any(Room.class)); assertEquals(room1.getPrice(), price); }