Skip to content

Commit

Permalink
Add leavecommand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 12, 2023
1 parent 8ecc94f commit dea32b5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/LeaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LeaveCommand extends Command {

public static final String MESSAGE_AMBIGUOUS = "Please check your MONTHS. Ambiguous leave(s) assignment\n";
public static final String MESSAGE_INVALID_MONTH = "Please check your MONTHS. Invalid month provided.\n";
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Leave(s) successfully updated for employee: %1$s";
public static final String MESSAGE_LEAVE_SUCCESS = "Leave(s) successfully updated for employee: %1$s";
public static final String MESSAGE_NOT_A_NUMBER = "Please check your MONTHS. Some is not a number.\n";
public static final String MESSAGE_NOT_EDITED = "The employee's leave(s) does not change from previous state: %1$s";
public static final String MESSAGE_SPACES_DETECTED = "Spaces detected in your MONTHS.\n";
Expand Down Expand Up @@ -75,7 +75,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setPerson(oldPerson, newPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(newPerson)));
return new CommandResult(String.format(MESSAGE_LEAVE_SUCCESS, Messages.format(newPerson)));
}

@Override
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/seedu/address/logic/commands/LeaveCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

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.person.Person;

public class LeaveCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private LeaveCommand leaveFirstCommand = new LeaveCommand(INDEX_FIRST_PERSON, "0000+0000000");
private LeaveCommand leaveSecondCommand = new LeaveCommand(INDEX_SECOND_PERSON, "0+0000000000");

@Test
public void equals() {
assertFalse(leaveFirstCommand.equals(null));
assertEquals(leaveFirstCommand, leaveFirstCommand);
assertFalse(leaveFirstCommand.equals(leaveSecondCommand));
assertFalse(leaveFirstCommand.toString().equals(""));
}

@Test
public void execute_success() {
Person person = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
String expected = String.format(LeaveCommand.MESSAGE_LEAVE_SUCCESS, Messages.format(person));
ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
assertCommandSuccess(leaveFirstCommand, model, expected, expectedModel);
}

@Test
public void execute_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
LeaveCommand command = new LeaveCommand(outOfBoundIndex, "0000+0000000");
assertCommandFailure(command, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);

Person person = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
assertCommandFailure(leaveSecondCommand, model,
String.format(LeaveCommand.MESSAGE_NOT_EDITED, person.getLeave().toString()));
}
}

0 comments on commit dea32b5

Please sign in to comment.