Skip to content

Commit

Permalink
Merge pull request #221 from AY1920S1-CS2103T-F11-2/J-final-testing
Browse files Browse the repository at this point in the history
Do up testing for implemented features
  • Loading branch information
JermyTan committed Nov 10, 2019
2 parents c3560a2 + 894fb87 commit af596f3
Show file tree
Hide file tree
Showing 31 changed files with 458 additions and 90 deletions.
1 change: 1 addition & 0 deletions src/main/java/io/xpire/commons/core/Messages.java
Expand Up @@ -13,4 +13,5 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_DELETE_MODE = "Unknown Delete mode.";
public static final String MESSAGE_SUGGESTIONS = " Did you mean %s?";
public static final String MESSAGE_REPLENISH_SHIFT_SUCCESS = "%s is shifted into the replenish list.";
public static final String MESSAGE_EMPTY_LIST = "Command not executed. The current list is empty!";
}
1 change: 1 addition & 0 deletions src/main/java/io/xpire/commons/util/DateUtil.java
Expand Up @@ -89,6 +89,7 @@ public static long getOffsetDays(LocalDate earlierDate, LocalDate laterDate) {
*/
public static LocalDate getPreviousDate(LocalDate date, int offsetDays) {
requireNonNull(date);
AppUtil.checkArgument(offsetDays >= 0);
return date.minusDays(offsetDays);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/xpire/logic/commands/CheckCommand.java
Expand Up @@ -5,6 +5,7 @@

import java.util.function.Predicate;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.Model;
import io.xpire.model.item.ExpiringSoonPredicate;
import io.xpire.model.item.ReminderThresholdExceededPredicate;
Expand Down Expand Up @@ -44,8 +45,9 @@ public CheckCommand(ReminderThresholdExceededPredicate predicate) {
}

@Override
public CommandResult execute(Model model, StateManager stateManager) {
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new FilteredState(model));

model.filterCurrentList(XPIRE, this.predicate);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/xpire/logic/commands/ClearCommand.java
Expand Up @@ -2,6 +2,7 @@

import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.ListType;
import io.xpire.model.Model;
import io.xpire.model.item.Item;
Expand Down Expand Up @@ -34,11 +35,12 @@ public ClearCommand(ListType listType) {
}

@Override
public CommandResult execute(Model model, StateManager stateManager) {
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireAllNonNull(model, stateManager);
stateManager.saveState(new ModifiedState(model));
this.requireNonEmptyCurrentList(model);

//remove list dependency on xpire/replenish internal list
stateManager.saveState(new ModifiedState(model));
//gets the current list and remove list dependency on xpire/replenish internal list
ObservableList<? extends Item> currentList = FXCollections.observableArrayList(model.getCurrentList());
currentList.forEach(item -> model.deleteItem(this.listType, item));
setShowInHistory(true);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/xpire/logic/commands/Command.java
@@ -1,5 +1,7 @@
package io.xpire.logic.commands;

import static io.xpire.commons.core.Messages.MESSAGE_EMPTY_LIST;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.logic.parser.exceptions.ParseException;
import io.xpire.model.Model;
Expand Down Expand Up @@ -40,4 +42,10 @@ public boolean isShowInHistory() {
public void setShowInHistory(boolean showInHistory) {
this.showInHistory = showInHistory;
}

protected void requireNonEmptyCurrentList(Model model) throws CommandException {
if (model.getCurrentList().isEmpty()) {
throw new CommandException(MESSAGE_EMPTY_LIST);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/xpire/logic/commands/CommandResult.java
Expand Up @@ -58,7 +58,7 @@ public CommandResult(String feedbackToUser) {
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser, boolean showQr, byte[] pngData) {
this(feedbackToUser, false, false, true, pngData);
this(feedbackToUser, false, false, showQr, pngData);
}

public String getFeedbackToUser() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/xpire/logic/commands/DeleteCommand.java
@@ -1,9 +1,9 @@
package io.xpire.logic.commands;

import static io.xpire.commons.core.Messages.MESSAGE_REPLENISH_SHIFT_SUCCESS;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;
import static io.xpire.model.ListType.REPLENISH;
import static io.xpire.model.ListType.XPIRE;
import static java.util.Objects.requireNonNull;

import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -87,7 +87,8 @@ public DeleteCommand(ListType listType, Index targetIndex, Quantity quantity) {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException, ParseException {
requireNonNull(model);
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new ModifiedState(model));
ObservableList<? extends Item> currentList = model.getCurrentList();

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/io/xpire/logic/commands/ExportCommand.java
Expand Up @@ -3,6 +3,7 @@
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;

import io.xpire.commons.util.StringUtil;
import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.Model;
import io.xpire.model.item.Item;
import io.xpire.model.state.StateManager;
Expand All @@ -24,14 +25,15 @@ public class ExportCommand extends Command {
public static final String SHOWING_EXPORT_MESSAGE = "QR code generated.";

/** Pretty formatting of the exported data. */
private static final String BORDER = "* * * * * * * * * * * * * * * * * * * * * * * * *\n";
public static final String BORDER = "* * * * * * * * * * * * * * * * * * * * * * * * *\n";

/** Resolution size of the QR code image. */
private static final int RESOLUTION_SIZE = 800;
public static final int RESOLUTION_SIZE = 800;

@Override
public CommandResult execute(Model model, StateManager stateManager) {
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);

ObservableList<? extends Item> currentList = model.getCurrentList();
StringBuilder formattedOutput = new StringBuilder(BORDER);
Expand All @@ -42,4 +44,13 @@ public CommandResult execute(Model model, StateManager stateManager) {
byte[] pngData = StringUtil.getQrCode(formattedOutput.toString(), RESOLUTION_SIZE);
return new CommandResult(SHOWING_EXPORT_MESSAGE, true, pngData);
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else {
return obj instanceof ExportCommand;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/xpire/logic/commands/RedoCommand.java
@@ -1,6 +1,6 @@
package io.xpire.logic.commands;

import static java.util.Objects.requireNonNull;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.Model;
Expand All @@ -19,7 +19,7 @@ public class RedoCommand extends Command {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireNonNull(model);
requireAllNonNull(model, stateManager);
if (stateManager.isNotRedoable()) {
throw new CommandException(MESSAGE_REDO_FAILURE);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/xpire/logic/commands/SearchCommand.java
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Collectors;

import io.xpire.commons.util.StringUtil;
import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.ListType;
import io.xpire.model.Model;
import io.xpire.model.item.ContainsKeywordsPredicate;
Expand Down Expand Up @@ -53,12 +54,13 @@ public SearchCommand(ListType listType, ContainsKeywordsPredicate predicate) {
}

@Override
public CommandResult execute(Model model, StateManager stateManager) {
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireAllNonNull(model, stateManager);
stateManager.saveState(new FilteredState(model));
this.requireNonEmptyCurrentList(model);

//Saves the current copy of the list view
ObservableList<? extends Item> previousList = FXCollections.observableArrayList(model.getCurrentList());
stateManager.saveState(new FilteredState(model));
//Updates the list view
model.filterCurrentList(this.listType, this.predicate);
//Retrieves the updated list view
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xpire/logic/commands/SetReminderCommand.java
Expand Up @@ -2,7 +2,6 @@

import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;
import static io.xpire.model.ListType.XPIRE;
import static java.util.Objects.requireNonNull;

import io.xpire.commons.core.Messages;
import io.xpire.commons.core.index.Index;
Expand Down Expand Up @@ -54,7 +53,8 @@ public SetReminderCommand(Index index, ReminderThreshold threshold) {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireNonNull(model);
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new ModifiedState(model));
ObservableList<? extends Item> currentList = model.getCurrentList();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/xpire/logic/commands/ShiftToMainCommand.java
@@ -1,9 +1,9 @@
package io.xpire.logic.commands;

import static io.xpire.commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;
import static io.xpire.model.ListType.REPLENISH;
import static io.xpire.model.ListType.XPIRE;
import static java.util.Objects.requireNonNull;

import java.util.List;

Expand Down Expand Up @@ -46,7 +46,8 @@ public ShiftToMainCommand(Index targetIndex, ExpiryDate expiryDate, Quantity qua

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireNonNull(model);
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new ModifiedState(model));

List<? extends Item> lastShownList = model.getCurrentList();
Expand Down
@@ -1,9 +1,9 @@
package io.xpire.logic.commands;

import static io.xpire.commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;
import static io.xpire.model.ListType.REPLENISH;
import static io.xpire.model.ListType.XPIRE;
import static java.util.Objects.requireNonNull;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -45,8 +45,8 @@ public ShiftToReplenishCommand(Index targetIndex) {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {

requireNonNull(model);
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new ModifiedState(model));
List<? extends Item> lastShownList = model.getCurrentList();

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/xpire/logic/commands/SortCommand.java
@@ -1,7 +1,8 @@
package io.xpire.logic.commands;

import static java.util.Objects.requireNonNull;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.Model;
import io.xpire.model.item.sort.XpireMethodOfSorting;
import io.xpire.model.state.FilteredState;
Expand Down Expand Up @@ -32,8 +33,9 @@ public SortCommand(XpireMethodOfSorting method) {
}

@Override
public CommandResult execute(Model model, StateManager stateManager) {
requireNonNull(model);
public CommandResult execute(Model model, StateManager stateManager)throws CommandException {
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);
stateManager.saveState(new FilteredState(model));
model.sortXpire(this.method);
//model.updateFilteredItemList(Model.PREDICATE_SORT_ALL_ITEMS);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/xpire/logic/commands/TagCommand.java
Expand Up @@ -93,7 +93,9 @@ public TagMode getMode() {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireAllNonNull(model);
requireAllNonNull(model, stateManager);
this.requireNonEmptyCurrentList(model);

switch (this.mode) {
case TAG:
return executeAddTags(model, stateManager);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xpire/logic/commands/UndoCommand.java
@@ -1,6 +1,6 @@
package io.xpire.logic.commands;

import static java.util.Objects.requireNonNull;
import static io.xpire.commons.util.CollectionUtil.requireAllNonNull;

import io.xpire.logic.commands.exceptions.CommandException;
import io.xpire.model.Model;
Expand All @@ -20,7 +20,7 @@ public class UndoCommand extends Command {

@Override
public CommandResult execute(Model model, StateManager stateManager) throws CommandException {
requireNonNull(model);
requireAllNonNull(model, stateManager);
if (stateManager.isNotUndoable()) {
throw new CommandException(MESSAGE_UNDO_FAILURE);
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public boolean test(Item item) {
tagsContainsKeywords = keyword.startsWith("#")
&& keyword.length() > 1
&& new HashSet<>(stringifyCollection(
item.getTags(), tag -> tag.substring(1, tag.length() - 1))
item.getTags(), tag -> tag.substring(1))
)
.contains(keyword.substring(1));
if (nameContainsKeywords || tagsContainsKeywords) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xpire/model/item/Item.java
Expand Up @@ -126,8 +126,8 @@ public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(this.name.toString());
if (!this.getTags().isEmpty()) {
builder.append("\nTags: ");
this.getTags().forEach((builder::append));
builder.append("\nTags:");
this.getTags().forEach(tag -> builder.append(" " + tag));
}
return builder.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xpire/model/item/XpireItem.java
Expand Up @@ -193,8 +193,8 @@ public String toString() {
builder.append(this.name).append("\n")
.append(String.format("Expiry date: %s\n", this.expiryDate.toStringWithCountdown()))
.append(String.format("Quantity: %s\n", this.quantity))
.append("Tags: ");
this.getTags().forEach(builder::append);
.append("Tags:");
this.getTags().forEach(tag -> builder.append(" " + tag));
} else {
builder.append(this.name).append("\n")
.append(String.format("Expiry date: %s\n", this.expiryDate.toStringWithCountdown()))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/xpire/model/tag/Tag.java
Expand Up @@ -67,7 +67,7 @@ public int hashCode() {
* Format state as text for viewing.
*/
public String toString() {
return "[" + this.tagName + "]";
return "#" + this.tagName;
}

}

0 comments on commit af596f3

Please sign in to comment.