-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCancelBookingHbsTest.java
124 lines (93 loc) · 3.92 KB
/
CancelBookingHbsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package STassgn;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@RunWith(JUnitParamsRunner.class)
public class CancelBookingHbsTest {
HotelBookingSystem hbs;
BookingRecordApplication braMock;
Booking bookingMock;
Room roomMock;
WaitingList waitingListMock;
User user;
DisplayUtilities duMock;
@Before
public void setup() {
hbs = new HotelBookingSystem();
duMock = mock(DisplayUtilities.class);
braMock = mock(BookingRecordApplication.class);
bookingMock = mock(Booking.class);
roomMock = mock(Room.class);
waitingListMock = mock(WaitingList.class);
hbs.setDu(duMock);
hbs.setBra(braMock);
hbs.setBooking(bookingMock);
hbs.setRoom(roomMock);
hbs.setWaitingList(waitingListMock);
}
User john = new User("John", "VIP", false);
User alice = new User("Alice", "Normal", true);
User bob = new User("Bob", "Non-member", false);
Booking booking1 = new Booking(john, "Deluxe");
Booking booking2 = new Booking(john, "VIP");
Booking booking3 = new Booking(alice, "Deluxe");
Booking booking4 = new Booking(bob, "Standard");
ArrayList<User> vipWaitingList = new ArrayList<User>();
ArrayList<User> memberWaitingList = new ArrayList<User>();
ArrayList<User> normalWaitingList = new ArrayList<User>();
private Object[] getParamsForTest() {
ArrayList<Booking> allBookings = new ArrayList<>();
allBookings.add(booking1);
allBookings.add(booking2);
allBookings.add(booking3);
allBookings.add(booking4);
ArrayList<Booking> johnBookings = new ArrayList<>();
johnBookings.add(booking1);
johnBookings.add(booking2); //VIP
ArrayList<Booking> aliceBookings = new ArrayList<>();
aliceBookings.add(booking3); //Deluxe
ArrayList<Booking> bobBookings = new ArrayList<>();
bobBookings.add(booking4); //Standard
return new Object[] {
new Object[] {john, allBookings, booking2},
new Object[] {alice, allBookings, booking3},
new Object[] {bob, allBookings, booking4}
};
}
@Test
@Parameters (method = "getParamsForTest")
public void testCancelBooking_NotInWaitingList(User user, ArrayList<Booking> allBookings, Booking bookingToRemove) {
//empty waiting lists
waitingListMock.vipWaitingList = new ArrayList<User>();
waitingListMock.memberWaitingList = new ArrayList<User>();
waitingListMock.normalWaitingList = new ArrayList<User>();
when(bookingMock.cancelBooking(allBookings, duMock)).thenReturn(bookingToRemove);
hbs.cancelBooking(allBookings);
assertFalse(allBookings.contains(bookingToRemove));
}
@Test
@Parameters (method = "getParamsForTest")
public void testCancelBooking_InWaitingList(User user, ArrayList<Booking> allBookings, Booking bookingToRemove) {
ArrayList<User> vipWaitingList = new ArrayList<>();
vipWaitingList.add(user);
waitingListMock.vipWaitingList = vipWaitingList;
waitingListMock.memberWaitingList = new ArrayList<>();
waitingListMock.normalWaitingList = new ArrayList<>();
assertTrue(waitingListMock.vipWaitingList.contains(user));
when(bookingMock.cancelBooking(allBookings, duMock)).thenReturn(bookingToRemove);
hbs.cancelBooking(allBookings);
assertFalse(waitingListMock.getWaiting("VIP").contains(user));
assertFalse(allBookings.contains(bookingToRemove));
}
}