forked from AY2324S1-CS2103T-T09-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AY2324S1-CS2103T-T09-2#250 from mingyu-wan/add-tes…
…t-cases Add test cases
- Loading branch information
Showing
15 changed files
with
769 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/test/java/seedu/address/logic/commands/RedoCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalClients.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.client.ClientRoles; | ||
import seedu.address.model.developer.DeveloperRoles; | ||
import seedu.address.testutil.ClientBuilder; | ||
|
||
public class RedoCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model modelAfterChange = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private RedoCommand redoCommand = new RedoCommand(); | ||
private UndoCommand undoCommand = new UndoCommand(); | ||
|
||
@Test | ||
public void execute_validRedo_success() throws CommandException { | ||
ClientBuilder clientBuilder = new ClientBuilder(); | ||
model.addClient(clientBuilder.build()); | ||
model.commitAddressBook(model, "Add Benson", TabIndex.Client); | ||
model.undoAddressBook(model); | ||
|
||
modelAfterChange = model; | ||
|
||
redoCommand.execute(model); | ||
|
||
assertEquals(model, modelAfterChange); // Ensure that the redo was successful | ||
} | ||
|
||
@Test | ||
public void execute_noRedoAvailable_throwsCommandException() { | ||
assertThrows(CommandException.class, () -> redoCommand.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_redoRoleCommand_success() throws CommandException { | ||
// Undo a command that added a new role for a client | ||
ClientRoles.addClientRole(new ClientRoles("NewRole")); | ||
model.commitAddressBook(model, "New role for client added: NewRole", TabIndex.Client); | ||
undoCommand.execute(model); | ||
|
||
// Redo the role addition | ||
redoCommand.execute(model); | ||
|
||
assertTrue(ClientRoles.isValidRole("NewRole")); | ||
ClientRoles.deleteClientRole(new ClientRoles("NewRole")); | ||
} | ||
|
||
@Test | ||
public void execute_redoDeveloperRoleCommand_success() throws CommandException { | ||
// Undo a command that added a new role for a developer | ||
DeveloperRoles.addDeveloperRole(new DeveloperRoles("NewRole")); | ||
model.commitAddressBook(model, "New role for developer added: NewRole", TabIndex.Developer); | ||
undoCommand.execute(model); | ||
|
||
// Redo the role addition | ||
redoCommand.execute(model); | ||
assertTrue(DeveloperRoles.isValidRole("NewRole")); | ||
DeveloperRoles.deleteDeveloperRole(new DeveloperRoles("NewRole")); | ||
} | ||
|
||
@Test | ||
public void execute_redoDeleteClientRoleCommand_success() throws CommandException { | ||
ClientRoles.addClientRole(new ClientRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "New role for client added: RoleToDelete", TabIndex.Client); | ||
|
||
// Undo a command that deleted a role for a client | ||
ClientRoles.deleteClientRole(new ClientRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "Role for clients deleted: RoleToDelete", TabIndex.Client); | ||
undoCommand.execute(model); | ||
|
||
// Redo the role deletion | ||
redoCommand.execute(model); | ||
|
||
assertFalse(ClientRoles.isValidRole("RoleToDelete")); | ||
} | ||
|
||
@Test | ||
public void execute_redoDeleteDeveloperRoleCommand_success() throws CommandException { | ||
DeveloperRoles.addDeveloperRole(new DeveloperRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "New role for developer added: NewRole", TabIndex.Developer); | ||
|
||
// Undo a command that deleted a role for a developer | ||
DeveloperRoles.deleteDeveloperRole(new DeveloperRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "Role for developers deleted: RoleToDelete", TabIndex.Developer); | ||
undoCommand.execute(model); | ||
|
||
// Redo the role deletion | ||
redoCommand.execute(model); | ||
|
||
assertFalse(DeveloperRoles.isValidRole("RoleToDelete")); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
src/test/java/seedu/address/logic/commands/UndoCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalClients.BOB; | ||
import static seedu.address.testutil.TypicalClients.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.client.ClientRoles; | ||
import seedu.address.model.developer.DeveloperRoles; | ||
import seedu.address.testutil.ClientBuilder; | ||
import seedu.address.testutil.DeveloperBuilder; | ||
|
||
public class UndoCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model modelAfterChange = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private UndoCommand undoCommand = new UndoCommand(); | ||
|
||
@Test | ||
public void execute_validUndo_success() throws CommandException { | ||
model.addClient(BOB); | ||
model.commitAddressBook(model, "Add Alice", TabIndex.Client); | ||
undoCommand.execute(model); | ||
assertEquals(model, modelAfterChange); | ||
} | ||
|
||
@Test | ||
public void execute_noUndoAvailable_throwsCommandException() { | ||
assertThrows(CommandException.class, () -> undoCommand.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_undoNonRoleCommand_success() throws CommandException { | ||
// Add a new role for a client | ||
ClientBuilder clientBuilder = new ClientBuilder(); | ||
model.addClient(clientBuilder.build()); | ||
model.commitAddressBook(model, "New client added", TabIndex.Client); | ||
|
||
// Undo the role addition | ||
undoCommand.execute(model); | ||
|
||
assertFalse(model.getFilteredClientList().contains(clientBuilder.build())); | ||
} | ||
|
||
@Test | ||
public void execute_undoClientRoleCommand_success() throws CommandException { | ||
// Add a new role for a client | ||
ClientRoles.addClientRole(new ClientRoles("NewRole")); | ||
model.commitAddressBook(model, "New role for client added: NewRole", TabIndex.Client); | ||
|
||
// Undo the role addition | ||
undoCommand.execute(model); | ||
|
||
assertFalse(ClientRoles.isValidRole("NewRole")); | ||
} | ||
|
||
@Test | ||
public void execute_undoNonDeveloperRoleCommand_success() throws CommandException { | ||
// Add a new role for a client | ||
DeveloperBuilder developerBuilder = new DeveloperBuilder(); | ||
model.addDeveloper(developerBuilder.build()); | ||
model.commitAddressBook(model, "New Developer Added", TabIndex.Developer); | ||
|
||
// Undo the role addition | ||
undoCommand.execute(model); | ||
|
||
assertFalse(model.getFilteredClientList().contains(developerBuilder.build())); | ||
} | ||
|
||
@Test | ||
public void execute_undoDeveloperRoleCommand_success() throws CommandException { | ||
// Add a new role for a client | ||
DeveloperRoles.addDeveloperRole(new DeveloperRoles("NewRole")); | ||
model.commitAddressBook(model, "New role for developer added: NewRole", TabIndex.Developer); | ||
|
||
// Undo the role addition | ||
undoCommand.execute(model); | ||
|
||
assertFalse(DeveloperRoles.isValidRole("NewRole")); | ||
} | ||
|
||
@Test | ||
public void execute_undoDeleteClientRoleCommand_success() throws CommandException { | ||
ClientRoles.addClientRole(new ClientRoles("NewRole")); | ||
model.commitAddressBook(model, "New role for client added: NewRole", TabIndex.Client); | ||
|
||
// Delete a role for a client | ||
ClientRoles.deleteClientRole(new ClientRoles("NewRole")); | ||
model.commitAddressBook(model, "Role for clients deleted: NewRole", TabIndex.Client); | ||
|
||
// Undo the role deletion | ||
undoCommand.execute(model); | ||
|
||
assertTrue(ClientRoles.isValidRole("NewRole")); | ||
ClientRoles.deleteClientRole(new ClientRoles("NewRole")); | ||
} | ||
|
||
@Test | ||
public void execute_undoDeleteDeveloperRoleCommand_success() throws CommandException { | ||
DeveloperRoles.addDeveloperRole(new DeveloperRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "New role for client added: NewRole", TabIndex.Developer); | ||
|
||
// Delete a role for a developer | ||
DeveloperRoles.deleteDeveloperRole(new DeveloperRoles("RoleToDelete")); | ||
model.commitAddressBook(model, "Role for developers deleted: RoleToDelete", TabIndex.Developer); | ||
|
||
// Undo the role deletion | ||
undoCommand.execute(model); | ||
|
||
assertTrue(DeveloperRoles.isValidRole("RoleToDelete")); | ||
DeveloperRoles.deleteDeveloperRole(new DeveloperRoles("RoleToDelete")); | ||
} | ||
} |
Oops, something went wrong.