Skip to content

Commit

Permalink
Add testcases for add functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahidharah committed Nov 11, 2023
1 parent 0ccf28e commit 4ec3ef8
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DeveloperRoles.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Frontend Developer
Backend Developer
Developer
r/
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ public class CommandTestUtil {
public static final String GITHUBID_DEC_BOB = " " + PREFIX_GITHUBID + VALID_GITHUBID_BOB;
public static final String RATING_DEC_AMY = " " + PREFIX_RATING + VALID_RATING_AMY;
public static final String RATING_DEC_BOB = " " + PREFIX_RATING + VALID_RATING_BOB;
public static final String ORGANISATION_DESC_AMY = " " + PREFIX_ORGANISATION + VALID_ORGANISATION_AMY;
public static final String ORGANISATION_DESC_BOB = " " + PREFIX_ORGANISATION + VALID_ORGANISATION_BOB;
public static final String ORGANISATION_DESC_CALEB = " " + PREFIX_ORGANISATION + VALID_ORGANISATION_CALEB;
public static final String ORGANISATION_DESC_DAN = " " + PREFIX_ORGANISATION + VALID_ORGANISATION_DAN;
public static final String DOCUMENT_DESC_AMY = " " + PREFIX_DOCUMENT + VALID_DOCUMENT_AMY;
public static final String DOCUMENT_DESC_BOB = " " + PREFIX_DOCUMENT + VALID_DOCUMENT_BOB;
public static final String DOCUMENT_DESC_CALEB = " " + PREFIX_DOCUMENT + VALID_DOCUMENT_CALEB;
public static final String DOCUMENT_DESC_DAN = " " + PREFIX_DOCUMENT + VALID_DOCUMENT_DAN;

Expand Down
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());
}
}

0 comments on commit 4ec3ef8

Please sign in to comment.