diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 60154600561..b4336e7c7bc 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -22,6 +22,12 @@ public class Messages { + "the funds the Employee currently has!"; public static final String MESSAGE_EMPTY_DEPARTMENT_FILTER = "department name cannot be empty!"; + public static final String MESSAGE_LIST_COMMAND_FORMAT = "list: Lists all the details of an organization’s employees, " + + "or list all employees of a specified department (case-insensitive).\n" + + "Parameters: [d/DEPARTMENT] (optional)\n" + + "Example: list (to list all employees) or " + + "list d/Engineering (to list all employees in Engineering department)"; + public static final String MESSAGE_LIST_SUCCESS = "Listed all employees (%1$d)"; public static final String MESSAGE_FILTER_SUCCESS = "Listed filtered employees (%1$d)"; diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParser.java index 45968f02c7d..b56b4fbf1ac 100644 --- a/src/main/java/seedu/address/logic/parser/ListCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ListCommandParser.java @@ -26,8 +26,15 @@ public ListCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DEPARTMENT); + if (argMultimap.getValue(PREFIX_DEPARTMENT).isEmpty()) { - return new ListCommand(); + try { + String secondArg = args.split(" ")[1]; + throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, + Messages.MESSAGE_LIST_COMMAND_FORMAT)); + } catch (IndexOutOfBoundsException e) { + return new ListCommand(); + } } try { Department filteringDepartment = new Department(argMultimap.getValue(PREFIX_DEPARTMENT).get()); diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 5a1ab3dbc0c..46c09c9f742 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -2,8 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.logic.Messages.*; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; @@ -85,7 +84,8 @@ public void parseCommand_help() throws Exception { @Test public void parseCommand_list() throws Exception { assertTrue(parser.parseCommand(ListCommand.COMMAND_WORD) instanceof ListCommand); - assertTrue(parser.parseCommand(ListCommand.COMMAND_WORD + " 3") instanceof ListCommand); + assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_LIST_COMMAND_FORMAT), () + -> parser.parseCommand(ListCommand.COMMAND_WORD + " 3")); } @Test