-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckBookingTest.java
118 lines (90 loc) · 3.33 KB
/
CheckBookingTest.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
package STassgn;
import static org.junit.Assert.*;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
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 org.junit.runners.Parameterized.Parameter;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@RunWith(JUnitParamsRunner.class)
public class CreateBookingTest {
DisplayUtilities duMock;
HotelBookingSystem hbs;
User userMock;
BookingRecordApplication braMock;
@Before
public void setup() {
duMock = mock(DisplayUtilities.class);
userMock = mock(User.class);
braMock = mock(BookingRecordApplication.class);
hbs = new HotelBookingSystem();
hbs.setDu(duMock);
hbs.setUser(userMock);
hbs.setBra(braMock);
}
private Object[] getParamsForTest() {
User john = new User("John", "VIP", true);
User alice = new User("Alice", "Normal", true);
User bob = new User("Bob", "Non-member", true);
Booking booking1 = new Booking(john, "Deluxe");
Booking booking2 = new Booking(john, "Standard");
Booking booking3 = new Booking(alice, "Standard");
Booking booking4 = new Booking(bob, "Standard");
ArrayList<Booking> allBookings1 = new ArrayList<>();
allBookings1.add(booking1);
allBookings1.add(booking2);
allBookings1.add(booking3);
allBookings1.add(booking4);
return new Object[] {
new Object[] {john, allBookings1},
new Object[] {alice, allBookings1},
new Object[] {bob, allBookings1}
};
}
@Test
@Parameters (method = "getParamsForTest")
public void testCreateBooking_MaxLimitNotReached_UserHaveExclReward(User user, ArrayList<Booking> allBookings) {
when(hbs.checkMaxBookingLimit(user)).thenReturn(true);
//called in checkMaxBookingLimit
when(braMock.getBookingRecords()).thenReturn(allBookings);
hbs.createBooking(user);
verify(duMock).showToScreen("\nPerforming booking for user: " + user.getName() + "\n");
verify(hbs).createWithExclReward();
}
private Object[] getParamsForTest2() {
User john = new User("John", "VIP", false);
User alice = new User("Alice", "Normal", false);
User bob = new User("Bob", "Non-member", false);
Booking booking1 = new Booking(john, "Deluxe");
Booking booking2 = new Booking(john, "Standard");
Booking booking3 = new Booking(alice, "Standard");
Booking booking4 = new Booking(bob, "Standard");
ArrayList<Booking> allBookings1 = new ArrayList<>();
allBookings1.add(booking1);
allBookings1.add(booking2);
allBookings1.add(booking3);
allBookings1.add(booking4);
return new Object[] {
new Object[] {john, allBookings1},
new Object[] {alice, allBookings1},
new Object[] {bob, allBookings1}
};
}
@Test
@Parameters (method = "getParamsForTest2")
public void testCreateBooking_MaxLimitNotReached_UserDontHaveExclReward(User user, ArrayList<Booking> allBookings) {
when(hbs.checkMaxBookingLimit(user)).thenReturn(true);
//called in checkMaxBookingLimit
when(braMock.getBookingRecords()).thenReturn(allBookings);
hbs.createBooking(user);
verify(duMock).showToScreen("\nPerforming booking for user: " + user.getName() + "\n");
verify(hbs).createWithoutExclReward();
}
}