Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#75 from tiif/branch-test-v1.2
Browse files Browse the repository at this point in the history
Created test for Lead and Client class
  • Loading branch information
LicongHuang authored Oct 19, 2023
2 parents 311f3e5 + 4941daf commit d9aceb9
Show file tree
Hide file tree
Showing 11 changed files with 923 additions and 27 deletions.
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ public void setPersons(List<Person> persons) {
this.persons.setPersons(persons);
}

/**
* Replaces the contents of the person list with {@code clients}.
* {@code clients} must not contain duplicate clients, use when loading clients from json.
*/
public void setClients(List<Client> clients) {
this.clients.setClients(clients);
}

/**
* Replaces the contents of the person list with {@code leads}.
* {@code leads} must not contain duplicate leads, use when loading leads from json.
*/
public void setLeads(List<Lead> leads) {
this.leads.setLeads(leads);
}
Expand All @@ -82,7 +90,7 @@ public void resetData(ReadOnlyAddressBook newData) {
*/
public boolean hasPerson(Person person) {
requireNonNull(person);
return clients.contains(person) || leads.contains(person);
return persons.contains(person);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,35 @@ public void equals() {
// different person -> returns false
assertFalse(addAliceCommand.equals(addBobCommand));
}
//test the difference between client and lead
@Test
public void equalsForClientandLeads() {
Person aliceClient = new PersonBuilder().withName("Alice").buildClient();
Person aliceLead = new PersonBuilder().withName("Alice").buildLead();
AddCommand addClientCommand = new AddCommand(aliceClient);
AddCommand addLeadCommand = new AddCommand(aliceLead);

// same object -> returns true
assertTrue(addClientCommand.equals(addClientCommand));

// same values -> returns true
AddCommand addAliceCommandCopy = new AddCommand(aliceClient);
assertTrue(addClientCommand.equals(addAliceCommandCopy));

// same values -> returns true
AddCommand addAliceLeadCommandCopy = new AddCommand(aliceLead);
assertTrue(addLeadCommand.equals(addAliceLeadCommandCopy));

// different types -> returns false
assertFalse(addClientCommand.equals(1));

// null -> returns false
assertFalse(addLeadCommand.equals(null));

// different person -> returns false
assertFalse(addClientCommand.equals(addLeadCommand));
}
//todo: test to string method for client and lead
@Test
public void toStringMethod() {
AddCommand addCommand = new AddCommand(ALICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.ListClientCommand.MESSAGE_SUCCESS;
import static seedu.address.testutil.TypicalClients.getTypicalClientsAddressBook;
import static seedu.address.testutil.TypicalLeads.getTypicalLeadsAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.function.Predicate;
Expand All @@ -16,22 +18,49 @@

public class ListClientCommandTest {

private Model model;
private Model expectedModel;
private Model personModel;
private Model expectedPersonModel;
private Model leadModel;
private Model expectedLeadModel;
private Model clientModel;
private Model expectedClientModel;

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

personModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedPersonModel = new ModelManager(personModel.getAddressBook(), new UserPrefs());
clientModel = new ModelManager(getTypicalClientsAddressBook(), new UserPrefs());
expectedClientModel = new ModelManager(clientModel.getAddressBook(), new UserPrefs());
leadModel = new ModelManager(getTypicalLeadsAddressBook(), new UserPrefs());
expectedLeadModel = new ModelManager(leadModel.getAddressBook(), new UserPrefs());

}
//filter list with both client and leads
@Test
public void execute_listIsFiltered_showsEverything() {
public void execute_personListIsFiltered_showsEverything() {
// Filter the model as required by ListClientCommand
Predicate<Person> predicate = ListClientCommand.CLIENT_TAG_PREDICATE;
model.updateFilteredPersonList(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListClientCommand(), model, MESSAGE_SUCCESS, expectedModel);
personModel.updateFilteredPersonList(predicate);
expectedPersonModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListClientCommand(), personModel, MESSAGE_SUCCESS, expectedPersonModel);
}
//filter list with only clients
@Test
public void execute_clientListIsFiltered_showsEverything() {
// Filter the model as required by ListClientCommand
Predicate<Person> predicate = ListClientCommand.CLIENT_TAG_PREDICATE;
clientModel.updateFilteredPersonList(predicate);
expectedClientModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListClientCommand(), clientModel, MESSAGE_SUCCESS, expectedClientModel);
}

//filter list with only leads
@Test
public void execute_leadListIsFiltered_showsEverything() {
// Filter the model as required by ListLeadCommand
Predicate<Person> predicate = ListClientCommand.CLIENT_TAG_PREDICATE;
leadModel.updateFilteredPersonList(predicate);
expectedLeadModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListClientCommand(), leadModel, ListClientCommand.MESSAGE_SUCCESS, expectedLeadModel);
}
}
49 changes: 39 additions & 10 deletions src/test/java/seedu/address/logic/commands/ListLeadCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.ListLeadCommand.MESSAGE_SUCCESS;
import static seedu.address.testutil.TypicalClients.getTypicalClientsAddressBook;
import static seedu.address.testutil.TypicalLeads.getTypicalLeadsAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.function.Predicate;
Expand All @@ -16,23 +18,50 @@

public class ListLeadCommandTest {

private Model model;
private Model expectedModel;

private Model personModel;
private Model expectedPersonModel;
private Model leadModel;
private Model expectedLeadModel;
private Model clientModel;
private Model expectedClientModel;
@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
personModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedPersonModel = new ModelManager(personModel.getAddressBook(), new UserPrefs());
leadModel = new ModelManager(getTypicalLeadsAddressBook(), new UserPrefs());
expectedLeadModel = new ModelManager(leadModel.getAddressBook(), new UserPrefs());
clientModel = new ModelManager(getTypicalClientsAddressBook(), new UserPrefs());
expectedClientModel = new ModelManager(clientModel.getAddressBook(), new UserPrefs());
}


@Test
public void execute_listIsFiltered_showsEverything() {
// Filter the model as required by ListClientCommand
public void execute_personListIsFiltered_showsEverything() {
// Filter the model as required by ListLeadCommand
Predicate<Person> predicate = ListLeadCommand.LEAD_TAG_PREDICATE;
personModel.updateFilteredPersonList(predicate);
expectedPersonModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListLeadCommand(), personModel, MESSAGE_SUCCESS, expectedPersonModel);
}

//filter list with only leads
@Test
public void execute_leadListIsFiltered_showsEverything() {
// Filter the model as required by ListLeadCommand
Predicate<Person> predicate = ListLeadCommand.LEAD_TAG_PREDICATE;
leadModel.updateFilteredPersonList(predicate);
expectedLeadModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListLeadCommand(), leadModel, ListLeadCommand.MESSAGE_SUCCESS, expectedLeadModel);
}

//filter list with only clients
@Test
public void execute_clientListIsFiltered_showsEverything() {
// Filter the model as required by ListLeadCommand
Predicate<Person> predicate = ListLeadCommand.LEAD_TAG_PREDICATE;
model.updateFilteredPersonList(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListLeadCommand(), model, MESSAGE_SUCCESS, expectedModel);
clientModel.updateFilteredPersonList(predicate);
expectedClientModel.updateFilteredPersonList(predicate);
assertCommandSuccess(new ListLeadCommand(), clientModel, MESSAGE_SUCCESS, expectedClientModel);
}
}

37 changes: 32 additions & 5 deletions src/test/java/seedu/address/model/AddressBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalClients.ALICE;
import static seedu.address.testutil.TypicalLeads.GEORGE;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.Arrays;
Expand Down Expand Up @@ -56,32 +57,58 @@ public void resetData_withDuplicatePersons_throwsDuplicatePersonException() {
assertThrows(DuplicatePersonException.class, () -> addressBook.resetData(newData));
}

@Test
public void resetData_withDuplicateLeads_throwsDuplicatePersonException() {
// Two persons with the same identity fields
Person editedGeorge = new PersonBuilder(GEORGE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.buildClient();
List<Person> newPersons = Arrays.asList(GEORGE, editedGeorge);
AddressBookStub newData = new AddressBookStub(newPersons);

assertThrows(DuplicatePersonException.class, () -> addressBook.resetData(newData));
}
@Test
public void hasPerson_nullPerson_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> addressBook.hasPerson(null));
}


@Test
public void hasPerson_personNotInAddressBook_returnsFalse() {
assertFalse(addressBook.hasPerson(ALICE));
}

@Test
// This test is not used as no longer adding person to addressbook
// @Test
public void hasLead_personNotInAddressBook_returnsFalse() {
assertFalse(addressBook.hasPerson(GEORGE));
}
@Test
public void hasPerson_personInAddressBook_returnsTrue() {
addressBook.addPerson(ALICE);
assertTrue(addressBook.hasPerson(ALICE));
}

// This test is not used as no longer adding person to addressbook
// @Test
@Test
public void hasLead_leadInAddressBook_returnsTrue() {
addressBook.addPerson(GEORGE);
assertTrue(addressBook.hasPerson(GEORGE));
}
@Test
public void hasPerson_personWithSameIdentityFieldsInAddressBook_returnsTrue() {
addressBook.addPerson(ALICE);
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.buildClient();
assertTrue(addressBook.hasPerson(editedAlice));
}

@Test
public void hasLead_leadWithSameIdentityFieldsInAddressBook_returnsTrue() {
addressBook.addPerson(GEORGE);
Person editedGeorge = new PersonBuilder(GEORGE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.buildLead();
assertTrue(addressBook.hasPerson(editedGeorge));
}

@Test
public void getPersonList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> addressBook.getPersonList().remove(0));
Expand Down
Loading

0 comments on commit d9aceb9

Please sign in to comment.