Skip to content

Commit

Permalink
Merge ea8e923 into 28efcf5
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidcwh committed Oct 29, 2019
2 parents 28efcf5 + ea8e923 commit ed821c3
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 29 deletions.
10 changes: 5 additions & 5 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ Usage:
=== Archiving past expenses: `archive`

. _Adding a record to an archive: archive add_ +
Transfers the expense at the specified index to the specified archive. +
If the specified archive does not exist, then the new archive is created before the expense is added. +
Transfers the expense at the specified index to your specified archive. +
If archive you entered does not exist, then the new archive is created before the expense is added. +
{nbsp} +
Usage:

Expand All @@ -237,7 +237,7 @@ Usage:
+
{nbsp} +
. _Listing records in a particular archive: archive list_ +
Displays the list of records in the specified archive +
Displays the list of records in your specified archive +
{nbsp} +
Usage:

Expand All @@ -249,7 +249,7 @@ Lists out all the records in the “2018 expenses” archive +
{nbsp} +

. _Deleting an archived record: archive delete_ +
Deletes the record at the specified index from a specified archive. +
Deletes the record at the specified index from your specified archive. +
If the archive record deleted was the last record in the archive, the empty archive will be deleted. +
{nbsp} +
Usage:
Expand All @@ -268,7 +268,7 @@ Deletes the record at the 5th index in the “2018 expenses” archive +
{nbsp} +

. _Revert/unarchive an archived record: archive revert_ +
Unarchives the record at the specified index from a specified archive, transferring it back to current list of expenses. +
Unarchives the record at the specified index from your specified archive, transferring it back to your current list of expenses. +
If the archive record reverted was the last record in the archive, the empty archive will be deleted. +
{nbsp} +
Usage:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/billboard/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Messages {
public static final String MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX = "The expense index provided is invalid";
public static final String MESSAGE_EXPENSES_LISTED_OVERVIEW = "%1$d expense(s) listed!";
public static final String MESSAGE_NONEXISTENT_ARCHIVE_ENTERED =
"There is no existing archive of the name provided";
"There is no existing archive of the name provided!";
public static final String MESSAGE_INVALID_ARCHIVE_NAME = "The archive name cannot be empty!";
public static final String MESSAGE_NOT_UNDOABLE = "There is no command to be undone.";
public static final String MESSAGE_NOT_REDOABLE = "There is no command to be redone.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public class AddArchiveCommand extends ArchiveCommand {
public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD
+ ": Creates an archive of the given name and\n"
+ "Adds the expense identified by the index number used in the displayed expense list to the archive\n"
+ ": Adds the expense identified by the index number used in the displayed expense list"
+ " to the given archive.\n"
+ "Given archive name must be prefixed by [" + PREFIX_ARCHIVE + "].\n"
+ "If the given archive name does not exist, a new archive will be created.\n"
+ "Example: " + ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD + " 2 " + PREFIX_ARCHIVE + "Groceries";

public static final String MESSAGE_SUCCESS_EXISTING_ARCHIVE = "[%1$s] added to [%2$s] archive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class DeleteArchiveCommand extends ArchiveCommand {
public static final String MESSAGE_USAGE = ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD
+ ": Deletes the archive expense identified by the index number used in "
+ "the archive displayed expense list.\n"
+ "Parameters: INDEX (must be a positive integer), ARCHIVE NAME (must be an existing archive)\n"
+ "Example: " + ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD + " 1" + PREFIX_ARCHIVE + "hobbies";
+ "Parameters: INDEX (must be a positive integer), ARCHIVE NAME (must be an existing archive"
+ " and prefixed with [" + PREFIX_ARCHIVE + "])\n"
+ "Example: " + ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD + " 1 " + PREFIX_ARCHIVE + "hobbies";

public static final String MESSAGE_DELETE_EXPENSE_SUCCESS = "Deleted [%1$s] expense in [%2$s] archive";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (archiveName.equals("")) {
throw new CommandException(Messages.MESSAGE_INVALID_ARCHIVE_NAME);
throw new CommandException(Messages.MESSAGE_INVALID_ARCHIVE_NAME + "\n" + MESSAGE_USAGE);
}

if (!model.hasArchive(archiveName)) {
throw new CommandException(Messages.MESSAGE_NONEXISTENT_ARCHIVE_ENTERED);
throw new CommandException(Messages.MESSAGE_NONEXISTENT_ARCHIVE_ENTERED + "\n" + MESSAGE_USAGE);
}

model.updateFilteredArchiveExpenses(archiveName, Model.PREDICATE_SHOW_ALL_EXPENSES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RevertArchiveCommand extends ArchiveCommand {

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Unarchives the expense identified by the index number used in the displayed archive expense list\n"
+ "Given archive name must be prefixed by [" + PREFIX_ARCHIVE + "].\n"
+ "Example: " + ArchiveCommand.COMMAND_WORD + " " + COMMAND_WORD + " 2 " + PREFIX_ARCHIVE + "Groceries";

public static final String MESSAGE_SUCCESS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static seedu.billboard.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.billboard.logic.parser.CliSyntax.PREFIX_ARCHIVE;

import java.util.NoSuchElementException;

import seedu.billboard.commons.core.index.Index;
import seedu.billboard.logic.commands.AddArchiveCommand;
import seedu.billboard.logic.parser.exceptions.ParseException;
Expand All @@ -21,12 +23,11 @@ public class AddArchiveCommandParser implements Parser<AddArchiveCommand> {
public AddArchiveCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_ARCHIVE);

try {
String archiveName = ParserUtil.parseArchive(argMultimap.getValue(PREFIX_ARCHIVE).get());
Index targetIndex = ParserUtil.parseIndex(argMultimap.getPreamble());
return new AddArchiveCommand(archiveName, targetIndex);
} catch (ParseException pe) {
} catch (ParseException | NoSuchElementException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddArchiveCommand.MESSAGE_USAGE), pe);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package seedu.billboard.logic.parser;

import static seedu.billboard.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.billboard.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -20,6 +17,9 @@
*/
public class ArchiveCommandParser implements Parser<ArchiveCommand> {

public static final String MESSAGE_ARCHIVE_COMMANDS = "Invalid archive command format! \nSupported commands:\n"
+ "add \ndelete \nrevert \nlist\nlistall \nFor more information:\n" + HelpCommand.MESSAGE_USAGE;

/**
* Used for initial separation of command word and args.
*/
Expand All @@ -36,7 +36,7 @@ public class ArchiveCommandParser implements Parser<ArchiveCommand> {
public ArchiveCommand parse(String userInput) throws ParseException {
final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
if (!matcher.matches()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
throw new ParseException(MESSAGE_ARCHIVE_COMMANDS);
}

final String commandWord = matcher.group("commandWord");
Expand All @@ -59,7 +59,7 @@ public ArchiveCommand parse(String userInput) throws ParseException {
return new DeleteArchiveCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
throw new ParseException(MESSAGE_ARCHIVE_COMMANDS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static seedu.billboard.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.billboard.logic.parser.CliSyntax.PREFIX_ARCHIVE;

import java.util.NoSuchElementException;

import seedu.billboard.commons.core.index.Index;
import seedu.billboard.logic.commands.DeleteArchiveCommand;
import seedu.billboard.logic.parser.exceptions.ParseException;
Expand All @@ -26,7 +28,7 @@ public DeleteArchiveCommand parse(String args) throws ParseException {
String archiveName = ParserUtil.parseArchive(argMultimap.getValue(PREFIX_ARCHIVE).get());
Index targetIndex = ParserUtil.parseIndex(argMultimap.getPreamble());
return new DeleteArchiveCommand(archiveName, targetIndex);
} catch (ParseException pe) {
} catch (ParseException | NoSuchElementException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteArchiveCommand.MESSAGE_USAGE), pe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static seedu.billboard.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.billboard.logic.parser.CliSyntax.PREFIX_ARCHIVE;

import java.util.NoSuchElementException;

import seedu.billboard.commons.core.index.Index;
import seedu.billboard.logic.commands.RevertArchiveCommand;
import seedu.billboard.logic.parser.exceptions.ParseException;
Expand All @@ -26,7 +28,7 @@ public RevertArchiveCommand parse(String args) throws ParseException {
String archiveName = ParserUtil.parseArchive(argMultimap.getValue(PREFIX_ARCHIVE).get());
Index targetIndex = ParserUtil.parseIndex(argMultimap.getPreamble());
return new RevertArchiveCommand(archiveName, targetIndex);
} catch (ParseException pe) {
} catch (ParseException | NoSuchElementException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, RevertArchiveCommand.MESSAGE_USAGE), pe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.billboard.logic.commands.CommandTestUtil.VALID_ARCHIVE_DINNER;
import static seedu.billboard.logic.commands.CommandTestUtil.VALID_ARCHIVE_TAXES;
import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.billboard.logic.commands.ListArchiveCommand.MESSAGE_USAGE;
import static seedu.billboard.testutil.Assert.assertThrows;
import static seedu.billboard.testutil.TypicalExpenses.getTypicalBillboardWithArchiveExpenses;

Expand Down Expand Up @@ -33,13 +34,14 @@ public void constructor_nullArchiveName_throwsNullPointerException() {
@Test
public void execute_invalidArchiveName_throwsCommandException() {
ListArchiveCommand listArchiveCommand = new ListArchiveCommand("");
assertCommandFailure(listArchiveCommand, model, Messages.MESSAGE_INVALID_ARCHIVE_NAME);
assertCommandFailure(listArchiveCommand, model, Messages.MESSAGE_INVALID_ARCHIVE_NAME + "\n" + MESSAGE_USAGE);
}

@Test
public void execute_existingArchiveName_throwsCommandException() {
ListArchiveCommand listArchiveCommand = new ListArchiveCommand("lalala");
assertCommandFailure(listArchiveCommand, model, Messages.MESSAGE_NONEXISTENT_ARCHIVE_ENTERED);
assertCommandFailure(listArchiveCommand, model,
Messages.MESSAGE_NONEXISTENT_ARCHIVE_ENTERED + "\n" + MESSAGE_USAGE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package seedu.billboard.logic.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.billboard.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.billboard.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.billboard.logic.commands.CommandTestUtil.VALID_ARCHIVE_TAXES;
import static seedu.billboard.logic.parser.ArchiveCommandParser.MESSAGE_ARCHIVE_COMMANDS;
import static seedu.billboard.testutil.Assert.assertThrows;
import static seedu.billboard.testutil.TypicalIndexes.INDEX_FIRST_EXPENSE;

import org.junit.jupiter.api.Test;

import seedu.billboard.logic.commands.AddArchiveCommand;
import seedu.billboard.logic.commands.HelpCommand;
import seedu.billboard.logic.commands.ListArchiveCommand;
import seedu.billboard.logic.commands.ListArchiveNamesCommand;
import seedu.billboard.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -40,12 +38,11 @@ public void parseCommand_addArchive_success() throws Exception {

@Test
public void parseCommand_unrecognisedInput_throwsParseException() {
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT,
HelpCommand.MESSAGE_USAGE), () -> parser.parse(""));
assertThrows(ParseException.class, MESSAGE_ARCHIVE_COMMANDS, () -> parser.parse(""));
}

@Test
public void parseCommand_unknownCommand_throwsParseException() {
assertThrows(ParseException.class, MESSAGE_UNKNOWN_COMMAND, () -> parser.parse("unknownCommand"));
assertThrows(ParseException.class, MESSAGE_ARCHIVE_COMMANDS, () -> parser.parse("unknownCommand"));
}
}

0 comments on commit ed821c3

Please sign in to comment.