From b01f23fc17c396833ba25ecbf7e2b3ce58407af2 Mon Sep 17 00:00:00 2001 From: Kailash201 <109354852+Kailash201@users.noreply.github.com> Date: Sat, 11 Nov 2023 16:31:34 +0800 Subject: [PATCH] fix test cases --- .../seedu/address/model/TimeIntervalList.java | 1 - .../duplicatePersonAddressBook.json | 42 +++++++++---- .../invalidPersonAddressBook.json | 28 +++++++-- .../typicalPersonsAddressBook.json | 62 ++++++++++++++++--- .../logic/commands/FindCommandTest.java | 2 +- .../logic/parser/AddCommandParserTest.java | 27 ++++---- .../logic/parser/FindCommandParserTest.java | 4 +- .../seedu/address/model/AddressBookTest.java | 4 +- .../seedu/address/testutil/TypicalGroups.java | 20 ++---- .../address/testutil/TypicalPersons.java | 21 ++++--- 10 files changed, 147 insertions(+), 64 deletions(-) diff --git a/src/main/java/seedu/address/model/TimeIntervalList.java b/src/main/java/seedu/address/model/TimeIntervalList.java index edcdf152cec..ae9993188e1 100644 --- a/src/main/java/seedu/address/model/TimeIntervalList.java +++ b/src/main/java/seedu/address/model/TimeIntervalList.java @@ -7,7 +7,6 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.person.Person; /** * Class representing the list of time intervals diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index a7427fe7aa2..496b2c99dc8 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -1,14 +1,34 @@ { - "persons": [ { - "name": "Alice Pauline", - "phone": "94351253", - "email": "alice@example.com", - "address": "123, Jurong West Ave 6, #08-111", - "tags": [ "friends" ] + "persons" : [ { + "name" : "Alice Pauline", + "phone" : "94351253", + "email" : "alice@example.com", + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { - "name": "Alice Pauline", - "phone": "94351253", - "email": "pauline@example.com", - "address": "4th street" - } ] + "name" : "Alice Pauline", + "phone" : "94351253", + "email" : "alice@example.com", + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] + } ], + "groups" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [ { + "start" : "MON 1200", + "end" : "MON 1400" + }, { + "start" : "WED 1600", + "end" : "THU 1800" + }], + "groupName" : "CS2105" + }] } diff --git a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json index ad3f135ae42..0ed3cb64985 100644 --- a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json @@ -1,8 +1,24 @@ { - "persons": [ { - "name": "Hans Muster", - "phone": "9482424", - "email": "invalid@email!3e", - "address": "4th street" - } ] + "persons" : [ { + "name" : "Alice Pauline", + "phone" : "94351253", + "email" : "alice@example.com", + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] + }], + "groups" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [ { + "start" : "MONddd 1200", + "end" : "MON 1400" + }, { + "start" : "WED 1600", + "end" : "THU 1800" + }], + "groupName" : "CS2105" + }] } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 2330b0b81de..0f56d6f961b 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -4,36 +4,82 @@ "name" : "Alice Pauline", "phone" : "94351253", "email" : "alice@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "Benson Meier", "phone" : "98765432", "email" : "johnd@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "Carl Kurz", "phone" : "95352563", "email" : "heinz@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "cornelia@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "Elle Meyer", "phone" : "9482224", "email" : "werner@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "Fiona Kunz", "phone" : "9482427", "email" : "lydia@example.com", - "groupList" : [ "CS2103T"] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] }, { "name" : "George Best", "phone" : "9482442", "email" : "anna@example.com", - "groupList" : [ "CS2103T"] - } ] + "groupList" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [], + "groupName" : "CS2105" + }], + "freeTimeList" : [ ] + } ], + "groups" : [ { + "groupRemark" : "CS2105 remark", + "meetingTimeList" : [ { + "start" : "MON 1200", + "end" : "MON 1400" + }, { + "start" : "WED 1600", + "end" : "THU 1800" + }], + "groupName" : "CS2105" + }] } diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index 63698799d29..4db56a5ddd9 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -78,7 +78,7 @@ public void execute_multipleKeywords_multiplePersonsFound() { public void toStringMethod() { NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); FindCommand findCommand = new FindPersonCommand(predicate); - String expected = FindCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; + String expected = FindPersonCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; assertEquals(expected, findCommand.toString()); } diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 654bfdb6455..4db967ff30d 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -59,14 +59,13 @@ public void parse_allFieldsPresent_success() { } @Test - public void parse_repeatedNonTagValue_failure() { - String validExpectedPersonString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB; + public void parse_repeated_failure() { + String validExpectedPersonString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GROUP_DESC_BOB; // multiple names assertParseFailure(parser, NAME_DESC_AMY + validExpectedPersonString, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME)); - // multiple phones assertParseFailure(parser, PHONE_DESC_AMY + validExpectedPersonString, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE)); @@ -75,28 +74,36 @@ public void parse_repeatedNonTagValue_failure() { assertParseFailure(parser, EMAIL_DESC_AMY + validExpectedPersonString, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EMAIL)); + // multiple groups + assertParseFailure(parser, GROUP_DESC_BOB + validExpectedPersonString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_GROUPTAG)); // multiple fields repeated assertParseFailure(parser, validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + validExpectedPersonString, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_EMAIL, PREFIX_PHONE)); + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_EMAIL, PREFIX_PHONE, PREFIX_GROUPTAG)); // invalid name - assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB, + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + GROUP_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC, + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + GROUP_DESC_BOB, Email.MESSAGE_CONSTRAINTS); // invalid phone - assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB, + assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + GROUP_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); + + // invalid group + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_GROUP_DESC, + Group.MESSAGE_CONSTRAINTS); + + } @Test public void parse_optionalFieldsMissing_success() { - // zero tags Person expectedPerson = new PersonBuilder(AMYWITHOUTGROUP).build(); assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY, new AddCommand(expectedPerson)); @@ -138,8 +145,6 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + GROUP_DESC_BOB, Email.MESSAGE_CONSTRAINTS); - // invalid address - // invalid group assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_GROUP_DESC, Group.MESSAGE_CONSTRAINTS); @@ -153,6 +158,6 @@ public void parse_invalidValue_failure() { String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + " " + PREFIX_GROUPTAG, String.format(MESSAGE_INVALID_COMMAND_FORMAT, Group.MESSAGE_CONSTRAINTS)); + + GROUP_DESC_BOB, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 4d73ef7781a..1754f29c588 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -27,10 +27,10 @@ public void parse_validArgs_returnsFindCommand() { // no leading and trailing whitespaces FindCommand expectedFindCommand = new FindPersonCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); - assertParseSuccess(parser, "Alice Bob", expectedFindCommand); + assertParseSuccess(parser, " n/Alice Bob", expectedFindCommand); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand); + assertParseSuccess(parser, " n/ Alice Bob ", expectedFindCommand); } } diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 72a81f9a3a0..15fcd1746eb 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -93,6 +93,8 @@ public void toStringMethod() { */ private static class AddressBookStub implements ReadOnlyAddressBook { private final ObservableList persons = FXCollections.observableArrayList(); + private final ObservableList groups = FXCollections.observableArrayList(); + AddressBookStub(Collection persons) { this.persons.setAll(persons); @@ -106,7 +108,7 @@ public ObservableList getPersonList() { //need to be edited @Override public ObservableList getGroupList() { - return getGroupList(); + return groups; } } diff --git a/src/test/java/seedu/address/testutil/TypicalGroups.java b/src/test/java/seedu/address/testutil/TypicalGroups.java index 9c9bd2de41e..43984313911 100644 --- a/src/test/java/seedu/address/testutil/TypicalGroups.java +++ b/src/test/java/seedu/address/testutil/TypicalGroups.java @@ -3,10 +3,11 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_GROUP_CS; import static seedu.address.logic.commands.CommandTestUtil.VALID_GROUP_CS2103T; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import seedu.address.model.group.Group; -import seedu.address.model.group.GroupList; import seedu.address.model.group.GroupRemark; /** @@ -26,20 +27,11 @@ public class TypicalGroups { .withTimeIntervalList("mon 1200 - mon 1400", "wed 1600 - thu 1800").build(); public static final Group CS2105 = new GroupBuilder().withName("CS2105") - .withGroupRemark("CS2105 remark").withListOfGroupMates("Avner", "Bernie", "Coin", "Dawson") - .withTimeIntervalList("mon 1200 - mon 1400", "wed 1600 - thu 1800").build(); - - - public static GroupList getTypicalPGroup() { - - GroupList groupList = new GroupList(); - Group[] groupArray = {CS2100, CS2102, CS2103, CS2105}; - - Arrays.stream(groupArray).forEach(groupList::add); - - return groupList; - + .withGroupRemark("CS2105 remark").withTimeIntervalList("mon 1200 - mon 1400", "wed 1600 - thu 1800") + .build(); + public static List getTypicalGroup() { + return new ArrayList<>(Arrays.asList(CS2105)); } } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index b6e37fdcd32..de15b0199ed 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -14,6 +14,7 @@ import java.util.List; import seedu.address.model.AddressBook; +import seedu.address.model.group.Group; import seedu.address.model.person.Person; /** @@ -24,26 +25,26 @@ public class TypicalPersons { public static final Person ALICE = new PersonBuilder().withName("Alice Pauline") .withEmail("alice@example.com") .withPhone("94351253") - .withGroupList("CS2103T").build(); + .withGroupList("CS2105").build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withEmail("johnd@example.com").withPhone("98765432") - .withGroupList("CS2103T").build(); + .withGroupList("CS2105").build(); public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563") - .withEmail("heinz@example.com").withGroupList("CS2103T").build(); + .withEmail("heinz@example.com").withGroupList("CS2105").build(); public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533") - .withEmail("cornelia@example.com").withGroupList("CS2103T").build(); + .withEmail("cornelia@example.com").withGroupList("CS2105").build(); public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224") - .withEmail("werner@example.com").withGroupList("CS2103T").build(); + .withEmail("werner@example.com").withGroupList("CS2105").build(); public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427") - .withEmail("lydia@example.com").withGroupList("CS2103T").build(); + .withEmail("lydia@example.com").withGroupList("CS2105").build(); public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442") - .withEmail("anna@example.com").withGroupList("CS2103T").build(); + .withEmail("anna@example.com").withGroupList("CS2105").build(); // Manually added public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424") - .withEmail("stefan@example.com").withGroupList("CS2103T").build(); + .withEmail("stefan@example.com").withGroupList("CS2105").build(); public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131") - .withEmail("hans@example.com").withGroupList("CS2103T").build(); + .withEmail("hans@example.com").withGroupList("CS2105").build(); // Manually added - Person's details found in {@code CommandTestUtil} public static final Person AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY) @@ -64,6 +65,8 @@ private TypicalPersons() {} // prevents instantiation */ public static AddressBook getTypicalAddressBook() { AddressBook ab = new AddressBook(); + Group group = TypicalGroups.getTypicalGroup().get(0); + ab.addGroup(group); for (Person person : getTypicalPersons()) { ab.addPerson(person); }