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.
- Loading branch information
1 parent
0ccf28e
commit 4ec3ef8
Showing
3 changed files
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Frontend Developer | ||
Backend Developer | ||
Developer | ||
r/ |
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
116 changes: 116 additions & 0 deletions
116
src/test/java/seedu/address/logic/commands/delete/DeleteClientCommandTest.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,116 @@ | ||
package seedu.address.logic.commands.delete; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.client.Client; | ||
import seedu.address.model.developer.Developer; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static seedu.address.logic.commands.CommandTestUtil.*; | ||
import static seedu.address.testutil.TypicalClients.getTypicalAddressBook; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for | ||
* {@code DeleteDeveloperCommand}. | ||
*/ | ||
public class DeleteClientCommandTest { | ||
|
||
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_validIndexUnfilteredList_success() { | ||
Client clientToDelete = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
DeleteClientCommand deleteClientCommand = new DeleteClientCommand(INDEX_FIRST_PERSON); | ||
|
||
String expectedMessage = String.format(DeleteClientCommand.MESSAGE_DELETE_CLIENT_SUCCESS, | ||
Messages.format(clientToDelete)); | ||
|
||
ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.deleteClient(clientToDelete); | ||
|
||
assertCommandSuccess(deleteClientCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexUnfilteredList_throwsCommandException() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredClientList().size() + 1); | ||
DeleteClientCommand deleteClientCommand = new DeleteClientCommand(outOfBoundIndex); | ||
|
||
assertCommandFailure(deleteClientCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void execute_validIndexFilteredList_success() { | ||
showClientAtIndex(model, INDEX_FIRST_PERSON); | ||
|
||
Client clientToDelete = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased()); | ||
DeleteClientCommand deleteClientCommand = new DeleteClientCommand(INDEX_FIRST_PERSON); | ||
|
||
String expectedMessage = String.format(DeleteClientCommand.MESSAGE_DELETE_CLIENT_SUCCESS, | ||
Messages.format(clientToDelete)); | ||
|
||
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
expectedModel.deleteClient(clientToDelete); | ||
showNoPerson(expectedModel); | ||
|
||
assertCommandSuccess(deleteClientCommand, model, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidIndexFilteredList_throwsCommandException() { | ||
showClientAtIndex(model, INDEX_FIRST_PERSON); | ||
|
||
Index outOfBoundIndex = INDEX_SECOND_PERSON; | ||
// ensures that outOfBoundIndex is still in bounds of address book list | ||
assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getClientList().size()); | ||
|
||
DeleteClientCommand deleteClientCommand = new DeleteClientCommand(outOfBoundIndex); | ||
|
||
assertCommandFailure(deleteClientCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
DeleteClientCommand deleteFirstCommand = new DeleteClientCommand(INDEX_FIRST_PERSON); | ||
DeleteClientCommand deleteSecondCommand = new DeleteClientCommand(INDEX_SECOND_PERSON); | ||
|
||
// same object -> returns true | ||
assertEquals(deleteFirstCommand, deleteFirstCommand); | ||
|
||
// same values -> returns true | ||
DeleteClientCommand deleteFirstCommandCopy = new DeleteClientCommand(INDEX_FIRST_PERSON); | ||
assertEquals(deleteFirstCommand, deleteFirstCommandCopy); | ||
|
||
// different types -> returns false | ||
assertNotEquals(1, deleteFirstCommand); | ||
|
||
// null -> returns false | ||
assertNotEquals(null, deleteFirstCommand); | ||
|
||
// different developer -> returns false | ||
assertNotEquals(deleteFirstCommand, deleteSecondCommand); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
Index targetIndex = Index.fromOneBased(1); | ||
DeleteClientCommand deleteClientCommand = new DeleteClientCommand(targetIndex); | ||
String expected = DeleteClientCommand.class.getCanonicalName() + "{targetIndex=" + targetIndex + "}"; | ||
assertEquals(expected, deleteClientCommand.toString()); | ||
} | ||
|
||
/** | ||
* Updates {@code model}'s filtered list to show no one. | ||
*/ | ||
private void showNoPerson(Model model) { | ||
model.updateFilteredClientList(p -> false); | ||
|
||
assertTrue(model.getFilteredClientList().isEmpty()); | ||
} | ||
} |