Skip to content

Commit

Permalink
Test cases and checkstyle done
Browse files Browse the repository at this point in the history
  • Loading branch information
waynefong0401 committed Oct 23, 2019
1 parent 69eb6b9 commit 11c3e81
Show file tree
Hide file tree
Showing 20 changed files with 265 additions and 107 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/billboard/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class Messages {
public static final String MESSAGE_NONEXISTENT_ARCHIVE_ENTERED =
"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.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,4 @@ public void setObservers(Set<Observer<? super T>> observers) {
this.observers.addAll(observers);
}

public ObservableData getClone() {
ObservableData<T> clonedData = new ObservableData<>();
clonedData.setValue(value);
clonedData.setObservers(observers);
return clonedData;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.billboard.logic.commands;

import seedu.billboard.logic.commands.exceptions.CommandException;
import seedu.billboard.model.Model;
import seedu.billboard.model.history.CommandHistory;

Expand All @@ -9,20 +8,19 @@
*/
public class HistoryCommand extends Command {
public static final String COMMAND_WORD = "history";
public static final String EMPTY_HISTORY = "There is no commandHistory.";
public static final String MESSAGE_EMPTY_HISTORY = "There is no command history.";


/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
@Override
public CommandResult execute(Model model) throws CommandException {
public CommandResult execute(Model model) {
if (!CommandHistory.hasCommand()) {
CommandResult cmdResult = new CommandResult(EMPTY_HISTORY);
return new CommandResult(MESSAGE_EMPTY_HISTORY);
}

CommandResult cmdResult = new CommandResult(CommandHistory.getCmdHistory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class RedoCommand extends Command {

public static final String COMMAND_WORD = "redo";
public static final String EMPTY_UNDO_LIST = "There is no command to be redone.";
public static final String MESSAGE_REDO_SUCCESS = COMMAND_WORD + ": %s";

/**
* Executes the command and returns the result message.
Expand All @@ -28,7 +29,7 @@ public CommandResult execute(Model model) throws CommandException {
String redoCmd = VersionedBillboard.getRedoCmd();
Model undoModel = VersionedBillboard.redo();
model.setModel(undoModel);
CommandResult cmdResult = new CommandResult(COMMAND_WORD + ": " + redoCmd);
CommandResult cmdResult = new CommandResult(String.format(MESSAGE_REDO_SUCCESS, redoCmd));
return cmdResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class UndoCommand extends Command {

public static final String COMMAND_WORD = "undo";
public static final String EMPTY_UNDO_LIST = "There is no command to be undone.";
public static final String MESSAGE_UNDO_SUCCESS = COMMAND_WORD + ": %s";

/**
* Executes the command and returns the result message.
Expand All @@ -28,7 +29,7 @@ public CommandResult execute(Model model) throws CommandException {
Model undoModel = VersionedBillboard.undo();
String undoCmd = VersionedBillboard.getUndoCmd();
model.setModel(undoModel);
CommandResult cmdResult = new CommandResult(COMMAND_WORD + ": " + undoCmd);
CommandResult cmdResult = new CommandResult(String.format(MESSAGE_UNDO_SUCCESS, undoCmd));
return cmdResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public Command parseCommand(String userInput) throws ParseException {
return new TagCommandParser().parse(arguments);

case UndoCommand.COMMAND_WORD:
return new UndoCommandParser().parse(arguments);
return new UndoCommand();

case RedoCommand.COMMAND_WORD:
return new RedoCommandParser().parse(arguments);
return new RedoCommand();

case HistoryCommand.COMMAND_WORD:
return new HistoryCommandParser().parse(arguments);
return new HistoryCommand();

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/seedu/billboard/logic/parser/RedoCommandParser.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/seedu/billboard/logic/parser/UndoCommandParser.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/seedu/billboard/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ public ModelManager() {
this(new Billboard(), new UserPrefs());
}

public ModelManager(Billboard billboard, ArchiveWrapper archives, UserPrefs userPrefs,
ObservableData<StatisticsType> statsType, FilteredList<Expense> filteredExpense,
HashMap<String, FilteredList<Expense>> filteredArchives) {
this.billboard = billboard;
this.archives = archives;
this.userPrefs = userPrefs;
this.statsType = statsType;
this.filteredExpense = filteredExpense;
this.filteredArchives = filteredArchives;
}

@Override
public Billboard getCombinedBillboard() {
List<Expense> combinedExpenses = new ArrayList<>();
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/seedu/billboard/model/history/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Object to store all the executed command.
*/
public class CommandHistory {
public static final String HAVE_HISTORY = "The following is the command history:";
public static final String HAVE_HISTORY = "The following is the command history:%s";
private static Stack<String> cmdList = new Stack<>();
private static int count = 0;

Expand Down Expand Up @@ -63,7 +63,7 @@ public static String peekPreviousCmd() {
* @return boolean return true if the cmdList is not empty.
*/
public static boolean hasCommand() {
return !cmdList.empty();
return cmdList.size() != 1;
}

/**
Expand All @@ -72,11 +72,19 @@ public static boolean hasCommand() {
* @return String return the string containing all the history commands.
*/
public static String getCmdHistory() {
String result = HAVE_HISTORY;
String result = "";
for (int i = cmdList.size() - 1; i > 0; i--) {
result = result.concat("\n\t");
result = result.concat(cmdList.get(i - 1));
}
return result;
return String.format(HAVE_HISTORY, result);
}

/**
* Clear command history.
*/
public static void clearHistory() {
cmdList.clear();
count = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Undo command List, store the previous model and command.
*/
public class VersionedBillboard {
protected static Stack<Model> modelList = new Stack<>();
protected static Stack<String> cmdList = new Stack<>();
protected static int currentState = 0;
private static Stack<Model> modelList = new Stack<>();
private static Stack<String> cmdList = new Stack<>();
private static int currentState = 0;

/**
* Saves the current address book state in state history.
Expand Down Expand Up @@ -68,7 +68,17 @@ public static String getRedoCmd() {
public static void clearList() {
modelList.clear();
cmdList.clear();
currentState = 0;
}

/**
* Compare the history of two Billboard states.
*/
public boolean compareBillboardModels(Stack<Model> modelList) {
return VersionedBillboard.modelList.equals(modelList);
}

public static void setCurrentState(int currentState) {
VersionedBillboard.currentState = currentState;
}
}
2 changes: 0 additions & 2 deletions src/test/java/seedu/billboard/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import seedu.billboard.model.ReadOnlyBillboard;
import seedu.billboard.model.UserPrefs;
import seedu.billboard.model.expense.Expense;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;
import seedu.billboard.storage.JsonBillboardStorage;
import seedu.billboard.storage.JsonUserPrefsStorage;
import seedu.billboard.storage.StorageManager;
Expand All @@ -41,7 +40,6 @@ public class LogicManagerTest {

private Model model = new ModelManager();
private Logic logic;
private VersionedBillboard versionedBillboard = new VersionedBillboard();

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.billboard.logic.commands;

import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.billboard.testutil.TypicalExpenses.getTypicalBillboard;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.billboard.model.Model;
import seedu.billboard.model.ModelManager;
import seedu.billboard.model.UserPrefs;
import seedu.billboard.model.history.CommandHistory;



class HistoryCommandTest {
private Model model;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalBillboard(), new UserPrefs());
CommandHistory.clearHistory();
CommandHistory.addCmdHistory("history");
}

@Test
void execute() {
//Empty history -> empty history message
HistoryCommand historyCommand = new HistoryCommand();
assertCommandSuccess(historyCommand, model, HistoryCommand.MESSAGE_EMPTY_HISTORY, model);
//Not empty history -> history records
CommandHistory.addCmdHistory("history");
assertCommandSuccess(historyCommand, model, String.format(CommandHistory.HAVE_HISTORY, "\n\thistory"), model);
}
}
41 changes: 41 additions & 0 deletions src/test/java/seedu/billboard/logic/commands/RedoCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package seedu.billboard.logic.commands;

import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.billboard.testutil.TypicalExpenses.getDeleteTypicalBillboard;
import static seedu.billboard.testutil.TypicalExpenses.getTypicalBillboard;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.billboard.commons.core.Messages;
import seedu.billboard.model.Model;
import seedu.billboard.model.ModelManager;
import seedu.billboard.model.UserPrefs;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;

class RedoCommandTest {
private Model model;
private RedoCommand redo;

@BeforeEach
void setUp() {
model = new ModelManager(getTypicalBillboard(), new UserPrefs());
VersionedBillboard.clearList();
VersionedBillboard.commit(model);
redo = new RedoCommand();
}

@Test
void execute() {
assertCommandFailure(redo, model, Messages.MESSAGE_NOT_REDOABLE);
Model deleteModel = new ModelManager(getDeleteTypicalBillboard(), new UserPrefs());
VersionedBillboard.commit(deleteModel);
String deleteCmd = "delete 1";
VersionedBillboard.addCmd(deleteCmd);
VersionedBillboard.undo();

String expectedMessage = String.format(RedoCommand.MESSAGE_REDO_SUCCESS, deleteCmd);
assertCommandSuccess(redo, model, expectedMessage, deleteModel);
}
}
34 changes: 34 additions & 0 deletions src/test/java/seedu/billboard/logic/commands/UndoCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package seedu.billboard.logic.commands;

import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.billboard.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.billboard.testutil.TypicalExpenses.getDeleteTypicalBillboard;
import static seedu.billboard.testutil.TypicalExpenses.getTypicalBillboard;

import org.junit.jupiter.api.Test;

import seedu.billboard.commons.core.Messages;
import seedu.billboard.model.Model;
import seedu.billboard.model.ModelManager;
import seedu.billboard.model.UserPrefs;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;

class UndoCommandTest {

@Test
void execute() {
Model model = new ModelManager(getTypicalBillboard(), new UserPrefs());
Model deleteModel = new ModelManager(getDeleteTypicalBillboard(), new UserPrefs());
Model expectedModel = new ModelManager(model.getBillboard(), new UserPrefs());
VersionedBillboard.clearList();
VersionedBillboard.commit(model);
UndoCommand undo = new UndoCommand();
assertCommandFailure(undo, model, Messages.MESSAGE_NOT_UNDOABLE);
VersionedBillboard.commit(deleteModel);
String deleteCmd = "delete 1";
VersionedBillboard.addCmd(deleteCmd);
String expectedMessage = String.format(UndoCommand.MESSAGE_UNDO_SUCCESS, deleteCmd);
assertCommandSuccess(undo, deleteModel, expectedMessage, expectedModel);
}

}
Loading

0 comments on commit 11c3e81

Please sign in to comment.