Skip to content

Commit

Permalink
Throw error message when list command format is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellaantania committed Oct 11, 2023
1 parent 85627ac commit 5a960fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a960fc

Please sign in to comment.