Skip to content

Commit

Permalink
Fixed add command
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiarena committed Apr 15, 2024
1 parent 0f1f5d0 commit 2142924
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LESSON;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_SUBJECT, PREFIX_REMARK,PREFIX_LESSON);
PREFIX_ADDRESS, PREFIX_SUBJECT, PREFIX_REMARK, PREFIX_LESSON);

if (arePrefixesPresent(argMultimap, PREFIX_LESSON)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_CONSTRAINTS));
throw new ParseException(String.format(AddCommand.MESSAGE_CONSTRAINTS));
}

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
Expand Down
15 changes: 1 addition & 14 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.LESSON_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.SUBJECT_DESC_MATHS;
Expand Down Expand Up @@ -72,18 +71,6 @@ public void execute_validCommand_success() throws Exception {
assertCommandSuccess(listCommand, ListCommand.MESSAGE_SUCCESS, model);
}

@Test
public void execute_storageThrowsIoException_throwsCommandException() {
assertCommandFailureForExceptionFromStorage(DUMMY_IO_EXCEPTION, String.format(
LogicManager.FILE_OPS_ERROR_FORMAT, DUMMY_IO_EXCEPTION.getMessage()));
}

@Test
public void execute_storageThrowsAdException_throwsCommandException() {
assertCommandFailureForExceptionFromStorage(DUMMY_AD_EXCEPTION, String.format(
LogicManager.FILE_OPS_PERMISSION_ERROR_FORMAT, DUMMY_AD_EXCEPTION.getMessage()));
}

@Test
public void getFilteredStudentList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredStudentList().remove(0));
Expand Down Expand Up @@ -168,7 +155,7 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)

// Triggers the saveAddressBook method by executing an add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + SUBJECT_DESC_MATHS + LESSON_DESC_AMY;
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + SUBJECT_DESC_MATHS;
Student expectedStudent = new StudentBuilder(AMY).build();
ModelManager expectedModel = new ModelManager();
expectedModel.addStudent(expectedStudent);
Expand Down
29 changes: 6 additions & 23 deletions src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_LESSON_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.LESSON_DESC_COMPLETED;
import static seedu.address.logic.commands.CommandTestUtil.LESSON_DESC_INCOMPLETE;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
Expand All @@ -23,8 +20,6 @@
import static seedu.address.logic.commands.CommandTestUtil.SUBJECT_DESC_SCIENCE;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_LESSON_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_LESSON_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_SUBJECT_BOB;
Expand All @@ -36,15 +31,14 @@
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.testutil.TypicalStudents.AMY;
import static seedu.address.testutil.TypicalStudents.BOB;
import static seedu.address.testutil.TypicalStudents.BOB_WITHOUT_LESSON;

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.AddCommand;
import seedu.address.model.student.Address;
import seedu.address.model.student.Email;
import seedu.address.model.student.Lesson;
import seedu.address.model.student.Name;
import seedu.address.model.student.Phone;
import seedu.address.model.student.Student;
Expand All @@ -55,25 +49,18 @@ public class AddCommandParserTest {

@Test
public void parse_allFieldsPresent_success() {
Student expectedStudent = new StudentBuilder(BOB).build();
Student expectedStudent = new StudentBuilder(BOB_WITHOUT_LESSON).build();

// whitespace only preamble
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ ADDRESS_DESC_BOB + SUBJECT_DESC_SCIENCE
+ REMARK_DESC_BOB + LESSON_DESC_COMPLETED, new AddCommand(expectedStudent));
// multiple lesson - all accepted
Student expectedStudentMultipleLessons = new StudentBuilder(BOB)
.withLessons(VALID_LESSON_BOB, VALID_LESSON_AMY).build();
assertParseSuccess(parser,
NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + SUBJECT_DESC_SCIENCE
+ REMARK_DESC_BOB + LESSON_DESC_COMPLETED + LESSON_DESC_INCOMPLETE,
new AddCommand(expectedStudentMultipleLessons));
+ REMARK_DESC_BOB, new AddCommand(expectedStudent));
}

@Test
public void parse_repeatedNonLessonValue_failure() {
String validExpectedStudentString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ ADDRESS_DESC_BOB + SUBJECT_DESC_SCIENCE + LESSON_DESC_COMPLETED;
+ ADDRESS_DESC_BOB + SUBJECT_DESC_SCIENCE;

// multiple names
assertParseFailure(parser, NAME_DESC_AMY + validExpectedStudentString,
Expand Down Expand Up @@ -164,7 +151,7 @@ public void parse_compulsoryFieldMissing_failure() {

// missing address prefix
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB
+ SUBJECT_DESC_MATHS + LESSON_DESC_INCOMPLETE,
+ SUBJECT_DESC_MATHS,
expectedMessage);

// all prefixes missing
Expand All @@ -191,18 +178,14 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC
+ SUBJECT_DESC_MATHS, Address.MESSAGE_CONSTRAINTS);

// invalid lesson
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ SUBJECT_DESC_MATHS + INVALID_LESSON_DESC, Lesson.MESSAGE_CONSTRAINTS_1);

// two invalid values, only first invalid value reported
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ INVALID_ADDRESS_DESC + SUBJECT_DESC_MATHS,
Name.MESSAGE_CONSTRAINTS);

// non-empty preamble
assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ ADDRESS_DESC_BOB + SUBJECT_DESC_MATHS + REMARK_DESC_BOB + LESSON_DESC_COMPLETED,
+ ADDRESS_DESC_BOB + SUBJECT_DESC_MATHS + REMARK_DESC_BOB,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
}
6 changes: 6 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalStudents.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class TypicalStudents {
.withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withLessons(VALID_LESSON_BOB)
.withSubject(VALID_SUBJECT_BOB).withRemark(VALID_REMARK_BOB).build();

public static final Student BOB_WITHOUT_LESSON = new StudentBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withSubject(VALID_SUBJECT_BOB)
.withRemark(VALID_REMARK_BOB).build();


public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

private TypicalStudents() {} // prevents instantiation
Expand Down

0 comments on commit 2142924

Please sign in to comment.