Skip to content

Commit

Permalink
Fix bug for storage test
Browse files Browse the repository at this point in the history
  • Loading branch information
howenc committed Nov 2, 2023
1 parent a863035 commit 4295ba7
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"_comment": "AddressBook save file which contains the same Person values as in TypicalPersons#getTypicalAddressBook()",
"persons" : [ {
"persons" : [{
"name" : "Bob Choo",
"phone" : "22222222",
"email" : "[email protected]",
"lastContactedTime" : "2023-09-20T12:00",
"status" : "prospective",
"tags" : [ "friend", "husband" ]
}, {
"name" : "Alice Pauline",
"phone" : "94351253",
"email" : "[email protected]",
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class EditCommandTest {

@Test
public void updateAttendees() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(firstPerson).withName("James").build();

Expand All @@ -62,7 +63,8 @@ public void updateAttendees() {

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Person editedPerson = new PersonBuilder().build();
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Person editedPerson = new PersonBuilder(model.getFilteredPersonList().get(0)).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor);

Expand All @@ -76,21 +78,22 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {

@Test
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size());
Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased());

PersonBuilder personInList = new PersonBuilder(lastPerson);
Index indexFirstPerson = Index.fromOneBased(1);
Person firstPerson = model.getFilteredPersonList().get(indexFirstPerson.getZeroBased());

PersonBuilder personInList = new PersonBuilder(firstPerson);
Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withTags(VALID_TAG_HUSBAND).build();

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build();
EditCommand editCommand = new EditCommand(indexLastPerson, descriptor);
EditCommand editCommand = new EditCommand(indexFirstPerson, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(lastPerson, editedPerson);
expectedModel.setPerson(firstPerson, editedPerson);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static seedu.address.testutil.TypicalAddressBook.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;
import static seedu.address.testutil.TypicalPersons.BOB;
import static seedu.address.testutil.TypicalPersons.CARL;
import static seedu.address.testutil.TypicalPersons.DANIEL;
import static seedu.address.testutil.TypicalPersons.ELLE;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void execute_zeroKeywords_allPersonFound() {
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, HOON),
assertEquals(Arrays.asList(BOB, ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, HOON),
model.getFilteredPersonList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,6 @@ public void execute_multipleTitleAndMultipleLocationKeywords_oneMeetingFound() {
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(MEETING2, MEETING3, MEETING4), model.getFilteredMeetingList());
}

@Test
public void execute_multipleTitleMultipleLocationAndAttendeeKeywords_twoMeetingFound() {
String expectedMessage = String.format(MESSAGE_MEETINGS_LISTED_OVERVIEW, 1);
GeneralMeetingPredicate predicate =
preparePredicate(new String[]{"ABCDE CS2101", "Zoom com", "Hoon", ""},
start, end);
FindMeetingCommand command = new FindMeetingCommand(predicate);
expectedModel.updateFilteredMeetingList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(MEETING4), model.getFilteredMeetingList());
}

@Test
public void execute_multipleTitleMultipleLocationAndMultipleAttendeeKeywords_twoMeetingFound() {
String expectedMessage = String.format(MESSAGE_MEETINGS_LISTED_OVERVIEW, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void execute_validIndexUnfilteredList_success() {
String expectedMessage = String.format(Messages.MESSAGE_PERSON_VIEWED_OVERVIEW, personToView.getName());
String expectedDisplayString = String.format(
"Name: %s\nPhone: %s\nEmail: %s\nLast Meeting: %s\nStatus: %s\nRemark: %s",
"Alice Pauline", "94351253", "alice@example.com", "20 October 2023, 1100", "NIL", "");
"Bob Choo", "22222222", "bob@example.com", "20 September 2023, 1200", "prospective", "");

ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());

Expand All @@ -60,7 +60,7 @@ public void execute_validIndexFilteredList_success() {
String expectedMessage = String.format(Messages.MESSAGE_PERSON_VIEWED_OVERVIEW, personToView.getName());
String expectedDisplayString = String.format(
"Name: %s\nPhone: %s\nEmail: %s\nLast Meeting: %s\nStatus: %s\nRemark: %s",
"Alice Pauline", "94351253", "alice@example.com", "20 October 2023, 1100", "NIL", "");
"Bob Choo", "22222222", "bob@example.com", "20 September 2023, 1200", "prospective", "");

// Model displaying filtered list should not change
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/testutil/TypicalAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ private TypicalAddressBook() {
public static AddressBook getTypicalAddressBook() {
AddressBook ab = new AddressBook();

for (Meeting meeting : TypicalMeetings.getTypicalMeetings()) {
ab.addMeeting(meeting);
}

for (Person person : TypicalPersons.getTypicalPersons()) {
ab.addPerson(person);
}

for (Meeting meeting : TypicalMeetings.getTypicalMeetings()) {
ab.addMeeting(meeting);
}

return ab;
}
}
1 change: 1 addition & 0 deletions src/test/java/seedu/address/testutil/TypicalMeetings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TypicalMeetings {
.withLocation("Zoom call url")
.withStart("20.09.2023 1000").withEnd("20.09.2023 1200")
.withTags("work", "important")
.withAttendees()
.build();

public static final Meeting MEETING2 = new MeetingBuilder().withTitle("CS2101 meeting")
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private TypicalPersons() {
} // prevents instantiation

public static List<Person> getTypicalPersons() {
return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, HOON));
return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, HOON, BOB));
}

/**
Expand All @@ -81,7 +81,7 @@ public static AddressBook getTypicalPersonsAddressBook() {
}

public static String[] getTypicalAttendeesAll() {
List<Person> typicalPersons = getTypicalPersons();
List<Person> typicalPersons = TypicalPersons.getTypicalPersons();
String[] typicalAttendees = typicalPersons.stream().map(Person::getName).map(Name::toString)
.collect(Collectors.toList()).toArray(String[]::new);
return typicalAttendees;
Expand Down

0 comments on commit 4295ba7

Please sign in to comment.