Skip to content

Commit

Permalink
Merge pull request #277 from Dandford/master
Browse files Browse the repository at this point in the history
Adding even more tests for CRUD For Category
  • Loading branch information
Dandford committed Nov 8, 2019
2 parents 5cb9715 + ce7667b commit ccb51e8
Show file tree
Hide file tree
Showing 53 changed files with 1,091 additions and 778 deletions.
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.addcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -55,9 +56,11 @@ public AddAutoExpenseCommand(AutoExpense autoExpense) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(toAdd.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}
model.addAutoExpense(toAdd);
model.createExpensesFromAutoExpenses();

model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.addcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -59,6 +60,9 @@ public AddBudgetCommand(Entry entry) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(toAdd.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}
model.addBudget((Budget) toAdd);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down
Expand Up @@ -10,6 +10,7 @@
import seedu.guilttrip.logic.commands.exceptions.CommandException;
import seedu.guilttrip.model.Model;
import seedu.guilttrip.model.entry.Category;
import seedu.guilttrip.model.entry.CategoryList;


/**
Expand Down Expand Up @@ -47,6 +48,10 @@ public AddCategoryCommand(Category entry) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (model.hasCategory(toAdd)) {
throw new CommandException(String.format(CategoryList.MESSAGE_CONSTRAINTS_IN_LIST,
toAdd.getCategoryType()));
}
model.addCategory(toAdd);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down

This file was deleted.

@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.addcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -57,6 +58,9 @@ public AddExpenseCommand(Expense expense) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(toAdd.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}
model.addExpense(toAdd);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.addcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -54,6 +55,9 @@ public AddIncomeCommand(Income income) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(toAdd.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}
model.addIncome(toAdd);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.addcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -53,6 +54,9 @@ public AddWishCommand(Wish wish) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(toAdd.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}
model.addWish(toAdd);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand Down
@@ -1,8 +1,10 @@
package seedu.guilttrip.logic.commands.deletecommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_EXISTING_ENTRIES_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
import static seedu.guilttrip.model.entry.CategoryList.MESSAGE_CONSTRAINTS_NOT_IN_LIST;

import seedu.guilttrip.logic.CommandHistory;
import seedu.guilttrip.logic.commands.Command;
Expand Down Expand Up @@ -39,6 +41,13 @@ public DeleteCategoryCommand(Category category) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
if (!model.hasCategory(targetCategory)) {
throw new CommandException(String.format(MESSAGE_CONSTRAINTS_NOT_IN_LIST,
targetCategory.getCategoryType()));
}
if (model.categoryHasAnyEntries(targetCategory)) {
throw new CommandException(MESSAGE_EXISTING_ENTRIES_CATEGORY);
}
model.deleteCategory(targetCategory);
model.commitGuiltTrip();
return new CommandResult(String.format(MESSAGE_DELETE_CATEGORY_SUCCESS, targetCategory));
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.editcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
Expand Down Expand Up @@ -80,6 +81,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

AutoExpense entryToEdit = lastShownList.get(index.getZeroBased());
AutoExpense editedEntry = createEditedAutoExpense(entryToEdit, editAutoExpenseDescriptor);
if (!model.hasCategory(editedEntry.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (!entryToEdit.isSameEntry(editedEntry) && model.hasAutoExpense(editedEntry)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.editcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class EditBudgetCommand extends Command {

public static final String MESSAGE_EDIT_ENTRY_SUCCESS = "Edited Budget: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_ENTRY = "This entry already exists in the guilttrip book.";
public static final String MESSAGE_DUPLICATE_ENTRY = "There is no change in the entry that you are editing.";

private final Index index;
private final EditBudgetDescriptor editEntryDescriptor;
Expand Down Expand Up @@ -80,6 +81,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Budget entryToEdit = lastShownList.get(index.getZeroBased());
Budget editedEntry = createEditedBudget(entryToEdit, editEntryDescriptor);
if (!model.hasCategory(editedEntry.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (entryToEdit.isSameBudget(editedEntry) && model.hasBudget(editedEntry)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
Expand Down
Expand Up @@ -3,7 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_TYPE;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_OLD_NAME;

import javafx.collections.ObservableList;
import seedu.guilttrip.logic.CommandHistory;
Expand All @@ -25,12 +25,12 @@ public class EditCategoryCommand extends Command {
public static final String MESSAGE_USAGE = ONE_LINER_DESC
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: "
+ PREFIX_TYPE + "TYPE OF CATEGORY "
+ PREFIX_CATEGORY + "CATEGORY NAME "
+ PREFIX_CATEGORY + "TYPE OF CATEGORY "
+ PREFIX_OLD_NAME + "CATEGORY OLD NAME "
+ PREFIX_DESC + "NEW NAME FOR CATEGORY "
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_TYPE + "Expense "
+ PREFIX_CATEGORY + "Food "
+ PREFIX_CATEGORY + "Expense "
+ PREFIX_OLD_NAME + "Food "
+ PREFIX_DESC + "Food And Drink ";

public static final String MESSAGE_EDIT_ENTRY_SUCCESS = "Edited Category: %1$s";
Expand All @@ -56,6 +56,7 @@ public EditCategoryCommand(Category toEditCategory, EditCategoryDescriptor editC
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
//ensures that the category old Name specified does not exist in GuiltTrip
if (!model.hasCategory(toEditCategory)) {
throw new CommandException(String.format(MESSAGE_NONEXISTENT_CATEGORY, toEditCategory.categoryType));
}
Expand All @@ -67,6 +68,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
//tbh alr checks
Category editedCategory = createEditedCategory(categoryToEdit, editCategoryDescriptor);
//TODO possible if doesn't work properly
//ensures that the new category specified does not exist in guilttrip
if (categoryToEdit.isSameCategory(editedCategory) || model.hasCategory(editedCategory)) {
throw new CommandException(MESSAGE_DUPLICATE_CATEGORY);
}
Expand Down Expand Up @@ -159,9 +161,8 @@ public boolean equals(Object other) {

// state check
EditCategoryDescriptor e = (EditCategoryDescriptor) other;

return getCategoryName().equals(e.getCategoryName())
&& getCategoryType().equals(e.getCategoryType());
&& getCategoryType().equalsIgnoreCase(e.getCategoryType());
}
}
}
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.editcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class EditExpenseCommand extends Command {

public static final String MESSAGE_EDIT_ENTRY_SUCCESS = "Edited Expense: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_ENTRY = "This expense already exists in guiltTrip.";
public static final String MESSAGE_DUPLICATE_ENTRY = "There is no change in the entry that you are editing.";

private final Index index;
private final EditExpenseDescriptor editEntryDescriptor;
Expand Down Expand Up @@ -80,11 +81,13 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Expense entryToEdit = lastShownList.get(index.getZeroBased());
Expense editedEntry = createEditedExpense(entryToEdit, editEntryDescriptor);
if (!model.hasCategory(editedEntry.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (!entryToEdit.isSameEntry(editedEntry) && model.hasExpense(editedEntry)) {
if (entryToEdit.isSameEntry(editedEntry) && model.hasExpense(editedEntry)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
}
System.out.println(editedEntry.toString());
model.setExpense(entryToEdit, editedEntry);
model.updateFilteredExpenses(PREDICATE_SHOW_ALL_EXPENSES);
model.commitGuiltTrip();
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.editcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
Expand Down Expand Up @@ -75,6 +76,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Income incomeToEdit = lastShownList.get(index.getZeroBased());
Income editedIncome = createEditedIncome(incomeToEdit, editIncomeDescriptor);
if (!model.hasCategory(editedIncome.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (incomeToEdit.isSameEntry(editedIncome) && model.hasIncome(editedIncome)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
Expand Down
@@ -1,6 +1,7 @@
package seedu.guilttrip.logic.commands.editcommands;

import static java.util.Objects.requireNonNull;
import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;
Expand Down Expand Up @@ -78,6 +79,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Wish entryToEdit = lastShownList.get(index.getZeroBased());
Wish editedEntry = createEditedWish(entryToEdit, editEntryDescriptor);
if (!model.hasCategory(editedEntry.getCategory())) {
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (!entryToEdit.isSameEntry(editedEntry) && model.hasWish(editedEntry)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
Expand Down

0 comments on commit ccb51e8

Please sign in to comment.