Skip to content

Commit ff1c69a

Browse files
authored
Merge pull request #184
2 parents 74559ef + 6611b3a commit ff1c69a

File tree

8 files changed

+267
-18
lines changed

8 files changed

+267
-18
lines changed

src/main/java/seedu/address/logic/commands/EditApplicationCommand.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ public boolean equals(Object other) {
191191
}
192192

193193
EditApplicationDescriptor editDescriptor = (EditApplicationDescriptor) other;
194-
return this.jobDescription.equals(editDescriptor.jobDescription)
195-
&& this.applicationStage.equals(editDescriptor.applicationStage)
196-
&& this.deadline.equals(editDescriptor.deadline)
197-
&& this.jobTitle.equals(editDescriptor.jobTitle)
198-
&& this.status.equals(editDescriptor.status);
194+
195+
// Objects.equals handles null cases as well.
196+
return Objects.equals(this.jobDescription, editDescriptor.jobDescription)
197+
&& Objects.equals(this.applicationStage, editDescriptor.applicationStage)
198+
&& Objects.equals(this.deadline, editDescriptor.deadline)
199+
&& Objects.equals(this.jobTitle, editDescriptor.jobTitle)
200+
&& Objects.equals(this.status, editDescriptor.status);
199201
}
200202
}
201203
}

src/test/java/seedu/address/logic/commands/ApplyCommandTest.java

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package seedu.address.logic.commands;
22

33
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
5+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
46
import static seedu.address.testutil.Assert.assertThrows;
57
import static seedu.address.testutil.TypicalContacts.NUS;
8+
import static seedu.address.testutil.TypicalContacts.RYAN;
69

710
import org.junit.jupiter.api.Test;
811

@@ -11,9 +14,9 @@
1114
import seedu.address.model.Model;
1215
import seedu.address.model.ModelManager;
1316
import seedu.address.model.contact.Id;
17+
import seedu.address.model.jobapplication.JobApplication;
1418
import seedu.address.model.jobapplication.JobTitle;
1519

16-
1720
public class ApplyCommandTest {
1821

1922
@Test
@@ -55,6 +58,7 @@ public void execute_indexOutOfBounds_throwsException() {
5558
@Test
5659
public void execute_noSuchId_throwsException() {
5760
Model model = new ModelManager();
61+
5862
assertThrows(
5963
CommandException.class, () -> new ApplyCommand(
6064
new Id(), null, new JobTitle("SWE"),
@@ -66,14 +70,15 @@ public void execute_noSuchId_throwsException() {
6670
@Test
6771
public void execute_applyToNonOrg_throwsException() {
6872
Model model = new ModelManager();
69-
model.addContact(NUS);
70-
assertThrows(
71-
CommandException.class, () -> new ApplyCommand(
72-
null, Index.fromOneBased(1), new JobTitle("SWE"),
73-
null, null, null,
74-
null)
75-
.execute(model)
76-
);
73+
model.addContact(RYAN);
74+
75+
String expectedMessage = String.format(ApplyCommand.MESSAGE_ATTEMPT_TO_ADD_TO_NON_ORG, RYAN);
76+
77+
ApplyCommand command = new ApplyCommand(
78+
null, Index.fromOneBased(1), new JobTitle("SWE"),
79+
null, null, null, null);
80+
81+
assertCommandFailure(command, model, expectedMessage);
7782
}
7883

7984
@Test
@@ -92,11 +97,41 @@ public void execute_noTitle_throwsException() {
9297
public void execute_validApplication_doesNotThrowException() {
9398
Model model = new ModelManager();
9499
model.addContact(NUS);
100+
101+
JobTitle uniqueJobTitle = new JobTitle("This is a unique job title");
102+
103+
JobApplication expectedApplication = new JobApplication(NUS, uniqueJobTitle,
104+
null, null, null);
105+
106+
ApplyCommand command = new ApplyCommand(null, Index.fromOneBased(1), uniqueJobTitle,
107+
null, null, null, null);
108+
109+
Model expectedModel = new ModelManager();
110+
expectedModel.addContact(NUS);
111+
expectedModel.addApplication(expectedApplication);
112+
113+
String expectedMessage = String.format(ApplyCommand.MESSAGE_APPLY_SUCCESS, expectedApplication, NUS);
114+
115+
assertCommandSuccess(command, model, expectedMessage, expectedModel);
116+
95117
assertDoesNotThrow(() -> new ApplyCommand(
96-
null, Index.fromOneBased(1), new JobTitle("SWE"),
118+
null, Index.fromOneBased(1), new JobTitle("This is a unique position"),
97119
null, null, null,
98120
null)
99121
.execute(model)
100122
);
101123
}
124+
125+
@Test
126+
public void execute_applicationWithSameName_throwException() {
127+
JobTitle title = NUS.getJobApplications()[0].getJobTitle();
128+
Model model = new ModelManager();
129+
model.addContact(NUS);
130+
131+
ApplyCommand command = new ApplyCommand(
132+
null, Index.fromOneBased(1), title,
133+
null, null, null, null);
134+
135+
assertCommandFailure(command, model, ApplyCommand.MESSAGE_DUPLICATE_APPLICATION);
136+
}
102137
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
package seedu.address.logic.commands;
22

3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
7+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
8+
import static seedu.address.testutil.TypicalContacts.getTypicalAddressBook;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import seedu.address.commons.core.index.Index;
13+
import seedu.address.logic.Messages;
14+
import seedu.address.model.Model;
15+
import seedu.address.model.ModelManager;
16+
import seedu.address.model.UserPrefs;
17+
import seedu.address.model.jobapplication.JobApplication;
18+
319
class DeleteApplicationCommandTest {
420

21+
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
22+
23+
@Test
24+
public void execute_validIndex_deletesApplication() {
25+
assert model.getDisplayedContactList().size() > 0;
26+
27+
JobApplication applicationToDelete = model.getDisplayedApplicationList().get(0);
28+
29+
DeleteApplicationCommand command = new DeleteApplicationCommand(Index.fromZeroBased(0));
30+
31+
String expectedMessage = String.format(DeleteApplicationCommand.MESSAGE_DELETE_APPLICATION_SUCCESS,
32+
applicationToDelete);
33+
34+
ModelManager expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
35+
36+
assertDoesNotThrow(() -> expectedModel.deleteApplication(applicationToDelete));
37+
38+
assertCommandSuccess(command, model, expectedMessage, expectedModel);
39+
}
40+
41+
@Test
42+
public void execute_invalidIndex_deletesApplication() {
43+
44+
DeleteApplicationCommand command = new DeleteApplicationCommand(Index.fromZeroBased(20));
45+
46+
String expectedMessage = Messages.MESSAGE_INVALID_APPLICATION_DISPLAYED_INDEX;
47+
48+
assertCommandFailure(command, model, expectedMessage);
49+
}
50+
51+
@Test
52+
public void equals() {
53+
54+
Index sharedIndex = Index.fromOneBased(1);
55+
DeleteApplicationCommand commandOne = new DeleteApplicationCommand(sharedIndex);
56+
DeleteApplicationCommand commandTwo = new DeleteApplicationCommand(sharedIndex);
57+
DeleteApplicationCommand commandThree = new DeleteApplicationCommand(Index.fromOneBased(2));
58+
59+
// equals itself
60+
assertEquals(commandOne, commandOne);
61+
62+
// equals same index
63+
assertEquals(commandOne, commandTwo);
64+
65+
// does not equal different index
66+
assertNotEquals(commandOne, commandThree);
67+
68+
// does not equal null
69+
assertNotEquals(commandOne, null);
70+
}
71+
572
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,109 @@
11
package seedu.address.logic.commands;
22

3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6+
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import seedu.address.commons.core.index.Index;
11+
import seedu.address.logic.Messages;
12+
import seedu.address.model.Model;
13+
import seedu.address.model.ModelManager;
14+
import seedu.address.model.UserPrefs;
15+
import seedu.address.model.jobapplication.JobApplication;
16+
import seedu.address.model.jobapplication.JobTitle;
17+
import seedu.address.testutil.TypicalContacts;
18+
319
class EditApplicationCommandTest {
420

21+
private Model model = new ModelManager(TypicalContacts.getTypicalAddressBook(), new UserPrefs());
22+
23+
private JobTitle uniqueTitle = new JobTitle("Unique title");
24+
@Test
25+
public void execute_validIndex_editSuccessfully() {
26+
27+
EditApplicationCommand.EditApplicationDescriptor editApplicationDescriptor =
28+
new EditApplicationCommand.EditApplicationDescriptor();
29+
30+
Model model = new ModelManager(TypicalContacts.getTypicalAddressBook(), new UserPrefs());
31+
32+
editApplicationDescriptor.setJobTitle(uniqueTitle);
33+
34+
EditApplicationCommand command = new EditApplicationCommand(Index.fromOneBased(1), editApplicationDescriptor);
35+
36+
assertDoesNotThrow(() -> command.execute(model));
37+
38+
JobApplication firstApplication = model.getDisplayedApplicationList().get(0);
39+
40+
assertEquals(uniqueTitle, firstApplication.getJobTitle());
41+
}
42+
43+
@Test
44+
public void execute_invalidIndex_throwsException() {
45+
46+
EditApplicationCommand.EditApplicationDescriptor editApplicationDescriptor =
47+
new EditApplicationCommand.EditApplicationDescriptor();
48+
49+
Model model = new ModelManager(TypicalContacts.getTypicalAddressBook(), new UserPrefs());
50+
51+
editApplicationDescriptor.setJobTitle(uniqueTitle);
52+
53+
EditApplicationCommand command = new EditApplicationCommand(Index.fromOneBased(20), editApplicationDescriptor);
54+
55+
assertCommandFailure(command, model, Messages.MESSAGE_INVALID_APPLICATION_DISPLAYED_INDEX);
56+
}
57+
58+
@Test
59+
public void execute_emptyFields_throwsException() {
60+
61+
EditApplicationCommand.EditApplicationDescriptor editApplicationDescriptor =
62+
new EditApplicationCommand.EditApplicationDescriptor();
63+
64+
Model model = new ModelManager(TypicalContacts.getTypicalAddressBook(), new UserPrefs());
65+
66+
EditApplicationCommand command = new EditApplicationCommand(Index.fromOneBased(20), editApplicationDescriptor);
67+
68+
assertCommandFailure(command, model, EditApplicationCommand.MESSAGE_NOT_EDITED);
69+
}
70+
71+
@Test
72+
public void equals() {
73+
EditApplicationCommand.EditApplicationDescriptor editApplicationDescriptorOne =
74+
new EditApplicationCommand.EditApplicationDescriptor();
75+
76+
EditApplicationCommand.EditApplicationDescriptor editApplicationDescriptorTwo =
77+
new EditApplicationCommand.EditApplicationDescriptor();
78+
79+
editApplicationDescriptorOne.setJobTitle(uniqueTitle);
80+
81+
Index one = Index.fromOneBased(1);
82+
83+
Index two = Index.fromOneBased(2);
84+
85+
EditApplicationCommand commandOne = new EditApplicationCommand(one, editApplicationDescriptorOne);
86+
EditApplicationCommand commandTwo = new EditApplicationCommand(one, editApplicationDescriptorOne);
87+
88+
// different index
89+
EditApplicationCommand commandThree = new EditApplicationCommand(two, editApplicationDescriptorOne);
90+
91+
// different descriptor
92+
EditApplicationCommand commandFour = new EditApplicationCommand(one, editApplicationDescriptorTwo);
93+
94+
// itself
95+
assertEquals(commandOne, commandOne);
96+
97+
// same index and descriptor
98+
assertEquals(commandOne, commandTwo);
99+
100+
// different index
101+
assertNotEquals(commandOne, commandThree);
102+
103+
// different descriptor
104+
assertNotEquals(commandOne, commandFour);
105+
106+
// null
107+
assertNotEquals(commandOne, null);
108+
}
5109
}

src/test/java/seedu/address/model/jobapplication/DeadlineTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77
import static seedu.address.testutil.Assert.assertThrows;
88

9+
import java.time.LocalDate;
10+
911
import org.junit.jupiter.api.Test;
1012

1113
public class DeadlineTest {
@@ -36,9 +38,9 @@ public void isValidDeadline() {
3638
String invalidDeadline5 = "29-02-2022";
3739
String invalidDeadline6 = "31-04-2022";
3840

39-
String validDeadline1 = "23-02-2022";
41+
String validDeadline1 = "29-02-2000";
4042
String validDeadline2 = "29-02-2020";
41-
String validDeadline3 = "30-04-2022";
43+
String validDeadline3 = "30-4-2022";
4244

4345
// null deadline
4446
assertThrows(NullPointerException.class, () -> Deadline.isValidDeadline(null));
@@ -62,10 +64,12 @@ public void compareTo() {
6264
Deadline d1 = new Deadline("22-11-2022");
6365
Deadline d2 = new Deadline("22-11-2022");
6466
Deadline d3 = new Deadline("11-12-2022");
67+
Deadline d4 = new Deadline(LocalDate.MAX);
6568

6669
assertEquals(d1.compareTo(d2), 0);
6770
assertTrue(d1.compareTo(d3) < 0);
6871
assertTrue(d3.compareTo(d1) > 0);
72+
assertTrue(d4.compareTo(d3) > 0);
6973
}
7074

7175
@Test

src/test/java/seedu/address/testutil/OrganizationBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package seedu.address.testutil;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
37
import seedu.address.model.contact.Organization;
8+
import seedu.address.model.jobapplication.JobApplication;
49

510
/**
611
* A utility class to help with building Organization objects.
712
*/
813
public class OrganizationBuilder extends ContactBuilder {
914

15+
private final List<JobApplication> applications = new ArrayList<>();
16+
1017
/**
1118
* Creates a {@code OrganizationBuilder} with the default details.
1219
*/
@@ -56,9 +63,17 @@ public OrganizationBuilder withUrl(String url) {
5663
return (OrganizationBuilder) super.withUrl(url);
5764
}
5865

66+
/**
67+
* Adds job applications to the organization we are building.
68+
*/
69+
public OrganizationBuilder withApplications(JobApplication... applications) {
70+
this.applications.addAll(Arrays.asList(applications));
71+
return this;
72+
}
73+
5974
@Override
6075
public Organization build() {
61-
return new Organization(name, id, phone, email, url, address, tags);
76+
return new Organization(name, id, phone, email, url, address, tags, applications);
6277
}
6378

6479
}

src/test/java/seedu/address/testutil/TypicalContacts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class TypicalContacts {
2222
.withUrl("www.nus.edu.sg")
2323
.withAddress("Computing 1, 13 Computing Drive")
2424
.withTags("computing", "worldClass")
25+
.withApplications(TypicalJobApplications.JOB_APPLICATIONS)
2526
.build();
2627

2728
public static final Organization NTU = new OrganizationBuilder()

0 commit comments

Comments
 (0)