-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCancelBookingTest.java
155 lines (120 loc) · 4.17 KB
/
CancelBookingTest.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package STassgn;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
@RunWith(JUnitParamsRunner.class)
public class CancelBookingTest {
private Booking booking;
private User userMock;
private DisplayUtilities duMock;
private Printer printer;
@Before
public void setup() {
userMock = mock(User.class);
duMock = mock(DisplayUtilities.class);
printer = new Printer();
printer.setDu(duMock);
}
User john = new User("John", "VIP", false);
User alice = new User("Alice", "Normal", true);
User bob = new User("Bob", "Non-normal", false);
Booking booking1 = new Booking(john, "VIP");
Booking booking2 = new Booking(alice, "Standard");
Booking booking3 = new Booking(bob, "Deluxe");
Booking booking4 = new Booking(john, "Standard");
private Object[] getParamsForTest() {
ArrayList<Booking> allBookings1 = new ArrayList<Booking>();
allBookings1.add(booking1);
allBookings1.add(booking2);
allBookings1.add(booking3);
allBookings1.add(booking4);
return new Object[] {
//John wants to cancel
new Object[] {allBookings1, john, booking4},
//Alice wants to cancel
new Object[] {allBookings1, alice, booking2},
//Bob wants to cancel
new Object[] {allBookings1, bob, booking3}
};
}
@Test
@Parameters (method = "getParamsForTest")
public void testCancelBooking_createdBookingBefore_chooseToCancel(ArrayList<Booking> allBookings, User user, Booking ER) {
when(userMock.getName()).thenReturn(user.getName());
when(duMock.getFromScreen()).thenReturn("Y");
//Call MUT
booking = new Booking(user, "Standard");
booking.setDu(duMock);
Booking AR = booking.cancelBooking(allBookings, duMock);
//verify(duMock).getFromScreen();
assertEquals(ER, AR);
}
private Object[] getParamsForTestNoCancel() {
ArrayList<Booking> allBookings1 = new ArrayList<Booking>();
allBookings1.add(booking1);
allBookings1.add(booking2);
allBookings1.add(booking3);
allBookings1.add(booking4);
return new Object[] {
//John wants to cancel
new Object[] {allBookings1, john},
//Alice wants to cancel
new Object[] {allBookings1, alice},
//Bob wants to cancel
new Object[] {allBookings1, bob}
};
}
@Test
@Parameters (method = "getParamsForTestNoCancel")
public void testCancelBooking_createdBookingBefore_chooseNotToCancel(ArrayList<Booking> allBookings, User user) {
when(userMock.getName()).thenReturn(user.getName());
when(duMock.getFromScreen()).thenReturn("N");
//Call MUT
booking = new Booking(user, "Standard");
booking.setDu(duMock);
Booking AR = booking.cancelBooking(allBookings, duMock);
//verify(duMock).getFromScreen();
assertNull(AR);
}
private Object[] getIllegalParamsForTest() {
//booking record without alice and bob
ArrayList<Booking> allBookings2 = new ArrayList<Booking>();
allBookings2.add(booking1);
allBookings2.add(booking4);
//booking record without john
ArrayList<Booking> allBookings3 = new ArrayList<Booking>();
allBookings3.add(booking2);
allBookings3.add(booking3);
//empty booking record
ArrayList<Booking> allBookings4 = new ArrayList<Booking>();
//other user record
User unknown = new User("Unknown", "VIP", true);
return new Object[] {
new Object[] {allBookings2, alice},
new Object[] {allBookings2, bob},
new Object[] {allBookings3, john},
new Object[] {allBookings4, john},
new Object[] {allBookings4, alice},
new Object[] {allBookings4, bob},
new Object[] {allBookings2, unknown},
new Object[] {allBookings3, unknown},
new Object[] {allBookings4, unknown}
};
}
@Test
@Parameters (method = "getIllegalParamsForTest")
public void testCancelBooking_noCreatedBookingBefore(ArrayList<Booking> allBookings, User user) {
when(userMock.getName()).thenReturn(user.getName());
//Call MUT
booking = new Booking(user, "Standard");
booking.setDu(duMock);
Booking AR = booking.cancelBooking(allBookings, duMock);
assertNull(AR);
}
}