Skip to content

Commit

Permalink
Merge pull request AY1920S1-CS2103T-F13-1#246 from linyutinglyt/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
hoholyin authored Nov 3, 2019
2 parents 12f7a9a + defe43a commit 7306e9f
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CommandResult execute(Model model) throws CommandException {

undoCommand = new EditBorrowerCommand(getBorrowerDescriptor(borrowerToEdit));
redoCommand = this;
commandResult = new CommandResult(String.format(MESSAGE_EDIT_BORROWER_SUCCESS, editedBorrower.toFullString()));
commandResult = new CommandResult(String.format(MESSAGE_EDIT_BORROWER_SUCCESS, editedBorrower));

return commandResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CommandResult execute(Model model) throws CommandException {

undoCommand = new UnregisterCommand(toAdd.getBorrowerId());
redoCommand = this;
commandResult = new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.toFullString()));
commandResult = new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));

return commandResult;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/commands/ServeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ServeCommand extends ReversibleCommand {
+ PREFIX_BORROWER_ID + "K0001 ";

public static final String MESSAGE_SUCCESS = "Currently serving Borrower: %1$s\n";
public static final String MESSAGE_ALREADY_IN_SERVE_MODE = "Currently still in serve mode! Please enter "
+ "\"done\" to exit serve mode before serving another borrower.";

private final BorrowerId borrowerId;

Expand All @@ -46,6 +48,10 @@ public ServeCommand (BorrowerId borrowerId) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.isServeMode()) {
throw new CommandException(MESSAGE_ALREADY_IN_SERVE_MODE);
}

if (!model.hasBorrowerId(borrowerId)) {
throw new CommandException(MESSAGE_NO_SUCH_BORROWER_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandResult execute(Model model) throws CommandException {

undoCommand = new RegisterCommand(toUnregister);
redoCommand = this;
commandResult = new CommandResult(String.format(MESSAGE_SUCCESS, toUnregister.toFullString()));
commandResult = new CommandResult(String.format(MESSAGE_SUCCESS, toUnregister));

return commandResult;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/parser/CatalogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import seedu.address.logic.commands.ServeCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.UnregisterCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -85,6 +86,9 @@ public Command parseCommand(String userInput) throws ParseException, CommandExce
case RegisterCommand.COMMAND_WORD:
return new RegisterCommandParser().parse(arguments);

case UnregisterCommand.COMMAND_WORD:
return new UnregisterCommandParser().parse(arguments);

case ServeCommand.COMMAND_WORD:
return new ServeCommandParser().parse(arguments);

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/borrower/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public class Email {
private static final String LOCAL_PART_REGEX = "^[\\w" + SPECIAL_CHARACTERS + "]+";
private static final String DOMAIN_FIRST_CHARACTER_REGEX = "[^\\W_]"; // alphanumeric characters except underscore
private static final String DOMAIN_MIDDLE_REGEX = "[a-zA-Z0-9.-]*"; // alphanumeric, period and hyphen
private static final String DOMAIN_LAST_CHARACTER_REGEX = "[^\\W_]$";
private static final String DOMAIN_LAST_CHARACTER_REGEX = "[^\\W_]{1,}$";
private static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@"
+ DOMAIN_FIRST_CHARACTER_REGEX + DOMAIN_MIDDLE_REGEX + DOMAIN_LAST_CHARACTER_REGEX;
+ DOMAIN_FIRST_CHARACTER_REGEX + DOMAIN_MIDDLE_REGEX + "\\."
+ DOMAIN_LAST_CHARACTER_REGEX;

public final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void execute_allFieldsSpecified_success() throws CommandException {
EditBorrowerCommand editBorrowerCommand = new EditBorrowerCommand(descriptor);

String expectedMessage = String.format(EditBorrowerCommand.MESSAGE_EDIT_BORROWER_SUCCESS,
editedBorrower.toFullString());
editedBorrower);

Model expectedModel = new ModelManager(
new Catalog(new Catalog()), new LoanRecords(), model.getBorrowerRecords(), new UserPrefs());
Expand All @@ -67,7 +67,7 @@ public void execute_someFieldsSpecified_success() throws CommandException {
EditBorrowerCommand editCommand = new EditBorrowerCommand(descriptor);

String expectedMessage = String.format(EditBorrowerCommand.MESSAGE_EDIT_BORROWER_SUCCESS,
editedBorrower.toFullString());
editedBorrower);

Model expectedModel = new ModelManager(
new Catalog(), new LoanRecords(), model.getBorrowerRecords(), new UserPrefs());
Expand All @@ -86,7 +86,7 @@ public void execute_noFieldSpecified_success() throws CommandException {
Borrower editedBorrower = model.getServingBorrower();

String expectedMessage = String.format(EditBorrowerCommand.MESSAGE_EDIT_BORROWER_SUCCESS,
editedBorrower.toFullString());
editedBorrower);

Model expectedModel = new ModelManager(
new Catalog(), new LoanRecords(), model.getBorrowerRecords(), new UserPrefs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void execute_borrowerAcceptedByModel_addSuccessful() throws Exception {

CommandResult commandResult = new RegisterCommand(validBorrower).execute(modelManager);

assertEquals(String.format(RegisterCommand.MESSAGE_SUCCESS, validBorrower.toFullString()),
assertEquals(String.format(RegisterCommand.MESSAGE_SUCCESS, validBorrower),
commandResult.getFeedbackToUser());
assertEquals(Arrays.asList(validBorrower), modelManager.getBorrowerRecords().getBorrowerList());
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/seedu/address/logic/commands/ServeCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_NO_SUCH_BORROWER_ID;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ID_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ID_BOB;
import static seedu.address.testutil.TypicalBorrowers.ALICE;
import static seedu.address.testutil.TypicalBorrowers.BOB;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -43,4 +44,17 @@ public void execute_borrowerIdNotFound_throwsCommandException() {
Assert.assertThrows(CommandException.class, MESSAGE_NO_SUCH_BORROWER_ID, () ->
serveCommand.execute(modelManager));
}

@Test
public void execute_alreadyInServeMode_throwsCommandException() throws CommandException {
Model modelManager = new ModelManager();
new RegisterCommand(BOB).execute(modelManager);
new RegisterCommand(ALICE).execute(modelManager);

new ServeCommand(ALICE.getBorrowerId()).execute(modelManager);
ServeCommand serveCommand = new ServeCommand(BOB.getBorrowerId());

Assert.assertThrows(CommandException.class, ServeCommand.MESSAGE_ALREADY_IN_SERVE_MODE, () ->
serveCommand.execute(modelManager));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void constructor_nullBorrowerId_throwsNullPointerException() {
public void execute_validSerialNumber_success() {
UnregisterCommand command = new UnregisterCommand(ID_FIRST_BORROWER);

String expectedMessage = String.format(UnregisterCommand.MESSAGE_SUCCESS, ALICE.toFullString());
String expectedMessage = String.format(UnregisterCommand.MESSAGE_SUCCESS, ALICE);

ModelManager expectedModel = new ModelManager(
model.getCatalog(), model.getLoanRecords(), model.getBorrowerRecords(), new UserPrefs());
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/seedu/address/logic/parser/CatalogParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SERIAL_NUMBER;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalBorrowers.ID_FIRST_BORROWER;
import static seedu.address.testutil.TypicalBorrowers.getTypicalBorrowerRecords;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_BOOK;

import org.junit.jupiter.api.Test;
Expand All @@ -36,6 +38,7 @@
import seedu.address.logic.commands.ReturnCommand;
import seedu.address.logic.commands.ServeCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.commands.UnregisterCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.BorrowerRecords;
import seedu.address.model.Catalog;
Expand Down Expand Up @@ -141,6 +144,14 @@ public void parseCommand_register() throws Exception {
instanceof RegisterCommand);
}

@Test
public void parseCommand_unregister() throws Exception {
BorrowerIdGenerator.setBorrowers(getTypicalBorrowerRecords());
assertTrue(parser.parseCommand(
UnregisterCommand.COMMAND_WORD + " " + PREFIX_BORROWER_ID + ID_FIRST_BORROWER)
instanceof UnregisterCommand);
}

@Test
public void parseCommand_serve() throws Exception {
assertTrue(parser.parseCommand(
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/seedu/address/model/borrower/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public void isValidEmail() {
assertFalse(Email.isValidEmail("[email protected].")); // domain name ends with a period
assertFalse(Email.isValidEmail("[email protected]")); // domain name starts with a hyphen
assertFalse(Email.isValidEmail("[email protected]")); // domain name ends with a hyphen

assertFalse(Email.isValidEmail("a@bc")); // no dot
assertFalse(Email.isValidEmail("peterjack@example.")); // nothing after dot
// valid email
assertTrue(Email.isValidEmail("[email protected]"));
assertTrue(Email.isValidEmail("a@bc")); // minimal
assertTrue(Email.isValidEmail("test@localhost")); // alphabets only
assertTrue(Email.isValidEmail("!#$%&'*+/=?`{|}~^[email protected]")); // special characters local part
assertTrue(Email.isValidEmail("123@145")); // numeric local part and domain name
assertTrue(Email.isValidEmail("[email protected]")); // mixture of alphanumeric and special characters
assertTrue(Email.isValidEmail("[email protected]")); // long domain name
assertTrue(Email.isValidEmail("[email protected]")); // long local part
Expand Down

0 comments on commit 7306e9f

Please sign in to comment.