Skip to content

Commit

Permalink
Updates tests to test department filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellaantania committed Oct 4, 2023
1 parent 8f26520 commit 3ff9944
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void execute_commandExecutionError_throwsCommandException() {
@Test
public void execute_validCommand_success() throws Exception {
String listCommand = ListCommand.COMMAND_WORD;
assertCommandSuccess(listCommand, ListCommand.MESSAGE_SUCCESS, model);
assertCommandSuccess(listCommand, String.format(
Messages.MESSAGE_LIST_SUCCESS, model.getFilteredPersonList().size()), model);
}

@Test
Expand Down
24 changes: 19 additions & 5 deletions src/test/java/seedu/address/logic/commands/ListCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.function.Predicate;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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.Department;
import seedu.address.model.person.MatchingDepartmentPredicate;
import seedu.address.model.person.Person;



/**
* Contains integration tests (interaction with the Model) and unit tests for ListCommand.
*/
public class ListCommandTest {

private static final Predicate<Person> FILTER_TEST_PREDICATE =
new MatchingDepartmentPredicate(new Department(VALID_DEPARTMENT));
private Model model;
private Model expectedModel;
private Model expectedFilteredModel;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedFilteredModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedFilteredModel.updateFilteredPersonList(FILTER_TEST_PREDICATE);
}

@Test
public void execute_listIsNotFiltered_showsSameList() {
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
assertCommandSuccess(new ListCommand(), model, String.format(
Messages.MESSAGE_LIST_SUCCESS, expectedModel.getFilteredPersonList().size()), expectedModel);
}

@Test
public void execute_listIsFiltered_showsEverything() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
assertCommandSuccess(new ListCommand(FILTER_TEST_PREDICATE), model, String.format(
Messages.MESSAGE_FILTER_SUCCESS, expectedFilteredModel.getFilteredPersonList().size()),
expectedFilteredModel);
}
}

0 comments on commit 3ff9944

Please sign in to comment.