forked from CS2103-AY1819S1-F10-1/main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddAssignmentCommandTest.java
326 lines (261 loc) · 11 KB
/
AddAssignmentCommandTest.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Predicate;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import javafx.collections.ObservableList;
import seedu.address.logic.CommandHistory;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyArchiveList;
import seedu.address.model.ReadOnlyAssignmentList;
import seedu.address.model.leaveapplication.LeaveApplicationWithEmployee;
import seedu.address.model.person.Person;
import seedu.address.model.person.User;
import seedu.address.model.project.Assignment;
import seedu.address.testutil.AssignmentBuilder;
public class AddAssignmentCommandTest {
private static final CommandHistory EMPTY_COMMAND_HISTORY = new CommandHistory();
@Rule
public ExpectedException thrown = ExpectedException.none();
private CommandHistory commandHistory = new CommandHistory();
@Test
public void constructor_nullPerson_throwsNullPointerException() {
thrown.expect(NullPointerException.class);
new AddAssignmentCommand(null);
}
@Test
public void execute_assignmentAcceptedByModel_addSuccessful() throws Exception {
AddAssignmentCommandTest.ModelStubAcceptingAssignmentAdded modelStub =
new AddAssignmentCommandTest.ModelStubAcceptingAssignmentAdded();
Assignment validAssignment = new AssignmentBuilder().build();
CommandResult commandResult = new AddAssignmentCommand(validAssignment).runBody(modelStub, commandHistory);
assertEquals(String.format(AddAssignmentCommand.MESSAGE_SUCCESS, validAssignment),
commandResult.getFeedbackToUser());
assertEquals(Arrays.asList(validAssignment), modelStub.assignmentsAdded);
assertEquals(EMPTY_COMMAND_HISTORY, commandHistory);
}
/*@Test
public void execute_duplicateAssignment_throwsCommandException() throws Exception {
Assignment validAssignment = new AssignmentBuilder().build();
AddAssignmentCommand addAssignmentCommand = new AddAssignmentCommand(validAssignment);
AddAssignmentCommandTest.ModelStub modelStub =
new AddAssignmentCommandTest.ModelStubWithAssignment(validAssignment);
thrown.expect(DuplicateAssignmentException.class);
thrown.expectMessage(AddAssignmentCommand.MESSAGE_DUPLICATE_ASSIGNMENT);
addAssignmentCommand.execute(modelStub, commandHistory);
}*/
@Test
public void equals() {
Assignment oasis = new AssignmentBuilder().withAssignmentName("OASIS").build();
Assignment falcon = new AssignmentBuilder().withAssignmentName("FALCON").build();
AddAssignmentCommand addOasisCommand = new AddAssignmentCommand(oasis);
AddAssignmentCommand addFalconCommand = new AddAssignmentCommand(falcon);
// same object -> returns true
assertTrue(addOasisCommand.equals(addOasisCommand));
// same values -> returns true
AddAssignmentCommand addOasisCommandCopy = new AddAssignmentCommand(oasis);
assertTrue(addOasisCommand.equals(addOasisCommandCopy));
// different types -> returns false
assertFalse(addOasisCommand.equals(1));
// null -> returns false
assertFalse(addOasisCommand.equals(null));
// different person -> returns false
assertFalse(addOasisCommand.equals(addFalconCommand));
}
/**
* A default model stub that have all of the methods failing.
*/
private class ModelStub implements Model {
@Override
public void addPerson(Person person) {
throw new AssertionError("This method should not be called.");
}
@Override
public int getState() {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean alreadyContainsUsername(String username, Person ignore) {
throw new AssertionError("This method should not be called.");
}
@Override
public void resetArchive(ReadOnlyArchiveList newData) {
throw new AssertionError("This method should not be called.");
}
@Override
public void resetData(ReadOnlyAddressBook newData) {
throw new AssertionError("This method should not be called.");
}
@Override
public ReadOnlyAddressBook getAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public ReadOnlyAssignmentList getAssignmentList() {
throw new AssertionError("This method should not be called.");
}
@Override
public ReadOnlyArchiveList getArchiveList() {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean hasPerson(Person person) {
throw new AssertionError("This method should not be called.");
}
@Override
public void deletePerson(Person target) {
throw new AssertionError("This method should not be called.");
}
@Override
public void deleteFromArchive(Person target) {
throw new AssertionError("This method should not be called.");
}
@Override
public void restorePerson(Person target) {
throw new AssertionError("This method should not be called.");
}
@Override
public void updatePerson(Person target, Person editedPerson) {
throw new AssertionError("This method should not be called.");
}
@Override
public User getLoggedInUser() {
throw new AssertionError("This method should not be called.");
}
@Override
public void setLoggedInUser(User u) {
throw new AssertionError("This method should not be called.");
}
@Override
public ObservableList<Person> getFilteredPersonList() {
throw new AssertionError("This method should not be called.");
}
@Override
public ObservableList<Person> getArchivedPersonList() {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateFilteredPersonList(Predicate<Person> predicate) {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateArchivedPersonList(Predicate<Person> predicate) {
throw new AssertionError("This method should not be called.");
}
@Override
public ObservableList<LeaveApplicationWithEmployee> getFilteredLeaveApplicationList() {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateFilteredLeaveApplicationList(Predicate<LeaveApplicationWithEmployee> predicate) {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateFilteredLeaveApplicationListForPerson(Person person) {
throw new AssertionError("This method should not be called.");
}
@Override
public ObservableList<Assignment> getFilteredAssignmentList() {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateFilteredAssignmentList(Predicate<Assignment> predicate) {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateFilteredAssignmentListForPerson(Person person) {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean canUndoAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean canRedoAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public void undoAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public void redoAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public void commitAddressBook() {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean hasAssignment(Assignment assignment) {
throw new AssertionError("This method should not be called.");
}
@Override
public void deleteAssignment(Assignment target) {
throw new AssertionError("This method should not be called.");
}
@Override
public void addAssignment(Assignment assignment) {
throw new AssertionError("This method should not be called.");
}
@Override
public void updateAssignment(Assignment target, Assignment editedAssignment) {
throw new AssertionError("This method should not be called.");
}
@Override
public boolean containsAssignment(String newAssignment, Assignment ignore) {
throw new AssertionError("This method should not be called.");
}
@Override
public void restartAddressBook() {
throw new AssertionError("This method should not be called.");
}
}
/**
* A Model stub that contains a single person.
*/
private class ModelStubWithAssignment extends AddAssignmentCommandTest.ModelStub {
private final Assignment assignment;
ModelStubWithAssignment(Assignment assignment) {
requireNonNull(assignment);
this.assignment = assignment;
}
@Override
public boolean hasAssignment(Assignment assignment) {
requireNonNull(assignment);
return this.assignment.isSameAssignment(assignment);
}
}
/**
* A Model stub that always accept the person being added.
*/
private class ModelStubAcceptingAssignmentAdded extends AddAssignmentCommandTest.ModelStub {
final ArrayList<Assignment> assignmentsAdded = new ArrayList<>();
@Override
public boolean hasAssignment(Assignment assignment) {
requireNonNull(assignment);
return assignmentsAdded.stream().anyMatch(assignment::isSameAssignment);
}
@Override
public void addAssignment(Assignment assignment) {
requireNonNull(assignment);
assignmentsAdded.add(assignment);
}
@Override
public void commitAddressBook() {
// called by {@code AddCommand#execute()}
}
@Override
public ReadOnlyAddressBook getAddressBook() {
return new AddressBook();
}
}
}