Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 22, 2023
1 parent 3643640 commit e30501d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RedoCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Redo the most recent command that was undone.";

private static final String MESSAGE_SUCCESS =
public static final String MESSAGE_SUCCESS =
"The last command that modified the employee list has been redone!\n"
+ "Successfully redone the following command: %1$s";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UndoCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Undo the most recent command that modified the employee list.";

private static final String MESSAGE_SUCCESS =
public static final String MESSAGE_SUCCESS =
"The last command that modified the employee list has been undone!\n"
+ "Successfully undone the following command: %1$s";

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/AddressBookList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Represents the history of AddressBook to allow undo and redo.
*/
public class AddressBookList extends ArrayList<AddressBook> {
private static final String REDO_ERROR_MESSAGE = "There is no command to redo! "
public static final String REDO_ERROR_MESSAGE = "There is no command to redo! "
+ "The command to be redone need to previously modified the employee list.";
private static final String UNDO_ERROR_MESSAGE = "There is no command to undo! "
public static final String UNDO_ERROR_MESSAGE = "There is no command to undo! "
+ "The command to be undone need to previously modified the employee list.";

private ArrayList<String> pastCommands = new ArrayList<String>();
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/seedu/address/logic/commands/RedoCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.address.logic.commands;

import org.junit.jupiter.api.Test;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;

import seedu.address.model.AddressBookList;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;

public class RedoCommandTest {
private Model model = new ModelManager();
private RedoCommand command = new RedoCommand();

@Test
public void execute_redo_success() {
model.addPerson(ALICE);
model.addCommandText("add Alice");
model.addPerson(BENSON);
model.addCommandText("add Benson");
model.undo();
assertCommandSuccess(command, model, String.format(RedoCommand.MESSAGE_SUCCESS, "add Benson"), model);
}

@Test
public void execute_redo_failure() {
assertCommandFailure(command, model, AddressBookList.REDO_ERROR_MESSAGE);
}
}
31 changes: 31 additions & 0 deletions src/test/java/seedu/address/logic/commands/UndoCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package seedu.address.logic.commands;

import org.junit.jupiter.api.Test;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;

import seedu.address.model.AddressBookList;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;

public class UndoCommandTest {
private Model model = new ModelManager();
private UndoCommand command = new UndoCommand();

@Test
public void execute_undo_success() {
model.addPerson(ALICE);
model.addCommandText("add Alice");
model.addPerson(BENSON);
model.addCommandText("add Benson");
assertCommandSuccess(command, model, String.format(UndoCommand.MESSAGE_SUCCESS, "add Benson"), model);
}

@Test
public void execute_undo_failure() {
assertCommandFailure(command, model, AddressBookList.UNDO_ERROR_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.LeaveCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.ViewLeaveCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
Expand Down Expand Up @@ -125,4 +127,13 @@ public void parseCommand_birthday_withoutMonth() throws Exception {
assertTrue(parser.parseCommand(BirthdayCommand.COMMAND_WORD) instanceof BirthdayCommand);
}

@Test
public void parseCommand_undo() throws Exception {
assertTrue(parser.parseCommand(UndoCommand.COMMAND_WORD) instanceof UndoCommand);
}

@Test
public void parseCommand_redo() throws Exception {
assertTrue(parser.parseCommand(RedoCommand.COMMAND_WORD) instanceof RedoCommand);
}
}
2 changes: 2 additions & 0 deletions src/test/java/seedu/address/model/AddressBookListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public void undo_success() {
addressBookList.add(new AddressBook());
addressBookList.add(new AddressBook());
assertEquals(addressBookList.undo(), new AddressBook());
addressBookList.add(new AddressBook());
assertEquals(addressBookList.undo(), new AddressBook());
}

@Test
Expand Down

0 comments on commit e30501d

Please sign in to comment.