Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#64 from FerdiHS/add-customers-…
Browse files Browse the repository at this point in the history
…testing

Fix unit testing for add customer command
  • Loading branch information
FerdiHS authored Oct 18, 2023
2 parents ad79f71 + 1db4b83 commit 15e526b
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 22 deletions.
21 changes: 21 additions & 0 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ public void getFilteredCustomerList_modifyList_throwsUnsupportedOperationExcepti
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredCustomerList().remove(0));
}

@Test
public void getAddressBookMethod() {
assertEquals(logic.getAddressBook(), model.getAddressBook());
}

@Test
public void getAddressBookFilePathMethod() {
assertEquals(logic.getAddressBookFilePath(), model.getAddressBookFilePath());
}

@Test
public void getGuiSettingsMethod() {
assertEquals(logic.getGuiSettings(), model.getGuiSettings());
}

@Test
public void setGuiSettingsMethod() {
logic.getGuiSettings();
model.getGuiSettings();
assertEquals(logic.getGuiSettings(), model.getGuiSettings());
}
/**
* Executes the command and confirms that
* - no exceptions are thrown <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.customer.Customer;
import seedu.address.testutil.CustomerBuilder;
Expand All @@ -23,14 +24,14 @@ public class AddCustomerCommandIntegrationTest {

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

@Test
public void execute_newCustomer_success() {
Customer validCustomer = new CustomerBuilder().build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
Model expectedModel = new ModelManager(model.getAddressBook(), new PropertyBook(), new UserPrefs());
expectedModel.addCustomer(validCustomer);

assertCommandSuccess(new AddCustomerCommand(validCustomer), model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyPropertyBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.customer.Customer;
import seedu.address.model.property.Property;
import seedu.address.testutil.CustomerBuilder;

public class AddCustomerCommandTest {
Expand Down Expand Up @@ -114,50 +116,99 @@ public Path getAddressBookFilePath() {
throw new AssertionError("This method should not be called.");
}

public Path getPropertyBookFilePath() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setAddressBookFilePath(Path addressBookFilePath) {
throw new AssertionError("This method should not be called.");
}

public void setPropertyBookFilePath(Path propertyBookFilePath) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addCustomer(Customer customer) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addProperty(Property property) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setAddressBook(ReadOnlyAddressBook newData) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setPropertyBook(ReadOnlyPropertyBook newData) {
throw new AssertionError("This method should not be called.");
}

@Override
public ReadOnlyAddressBook getAddressBook() {
throw new AssertionError("This method should not be called.");
}

@Override
public ReadOnlyPropertyBook getPropertyBook() {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasCustomer(Customer customer) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasProperty(Property property) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteCustomer(Customer target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteProperty(Property target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setCustomer(Customer target, Customer editedCustomer) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setProperty(Property target, Property editedProperty) {
throw new AssertionError("This method should not be called.");
}


@Override
public ObservableList<Customer> getFilteredCustomerList() {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Property> getFilteredPropertyList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredCustomerList(Predicate<Customer> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredPropertyList(Predicate<Property> predicate) {
throw new AssertionError("This method should not be called.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;

public class ClearCommandTest {
Expand All @@ -22,8 +23,8 @@ public void execute_emptyAddressBook_success() {

@Test
public void execute_nonEmptyAddressBook_success() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Model model = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());
expectedModel.setAddressBook(new AddressBook());

assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.customer.Customer;

Expand All @@ -25,7 +26,7 @@
*/
public class DeleteCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model model = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());

@Test
public void execute_validIndexUnfilteredList_success() {
Expand All @@ -35,7 +36,7 @@ public void execute_validIndexUnfilteredList_success() {
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_CUSTOMER_SUCCESS,
Messages.format(customerToDelete));

ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
ModelManager expectedModel = new ModelManager(model.getAddressBook(), new PropertyBook(), new UserPrefs());
expectedModel.deleteCustomer(customerToDelete);

assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);
Expand All @@ -59,7 +60,7 @@ public void execute_validIndexFilteredList_success() {
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_CUSTOMER_SUCCESS,
Messages.format(customerToDelete));

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
Model expectedModel = new ModelManager(model.getAddressBook(), new PropertyBook(), new UserPrefs());
expectedModel.deleteCustomer(customerToDelete);
showNoCustomer(expectedModel);

Expand Down
15 changes: 10 additions & 5 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.customer.Customer;
import seedu.address.testutil.CustomerBuilder;
Expand All @@ -33,7 +34,7 @@
*/
public class EditCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model model = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Expand All @@ -44,7 +45,8 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
Messages.format(editedCustomer));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
new PropertyBook(), new UserPrefs());
expectedModel.setCustomer(model.getFilteredCustomerList().get(0), editedCustomer);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
Expand All @@ -66,7 +68,8 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
Messages.format(editedCustomer));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
new PropertyBook(), new UserPrefs());
expectedModel.setCustomer(lastCustomer, editedCustomer);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
Expand All @@ -80,7 +83,8 @@ public void execute_noFieldSpecifiedUnfilteredList_success() {
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
Messages.format(editedCustomer));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
new PropertyBook(), new UserPrefs());

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}
Expand All @@ -97,7 +101,8 @@ public void execute_filteredList_success() {
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
Messages.format(editedCustomer));

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
new PropertyBook(), new UserPrefs());
expectedModel.setCustomer(model.getFilteredCustomerList().get(0), editedCustomer);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.customer.NameContainsKeywordsPredicate;

/**
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class FindCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model model = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new PropertyBook(), new UserPrefs());

@Test
public void equals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.PropertyBook;
import seedu.address.model.UserPrefs;

/**
Expand All @@ -22,8 +23,8 @@ public class ListCommandTest {

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

@Test
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/seedu/address/model/ModelManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void equals() {
UserPrefs userPrefs = new UserPrefs();

// same values -> returns true
modelManager = new ModelManager(addressBook, userPrefs);
ModelManager modelManagerCopy = new ModelManager(addressBook, userPrefs);
modelManager = new ModelManager(addressBook, new PropertyBook(), userPrefs);
ModelManager modelManagerCopy = new ModelManager(addressBook, new PropertyBook(), userPrefs);
assertTrue(modelManager.equals(modelManagerCopy));

// same object -> returns true
Expand All @@ -114,19 +114,19 @@ public void equals() {
assertFalse(modelManager.equals(5));

// different addressBook -> returns false
assertFalse(modelManager.equals(new ModelManager(differentAddressBook, userPrefs)));
assertFalse(modelManager.equals(new ModelManager(differentAddressBook, new PropertyBook(), userPrefs)));

// different filteredList -> returns false
String[] keywords = ALICE.getName().fullName.split("\\s+");
modelManager.updateFilteredCustomerList(new NameContainsKeywordsPredicate(Arrays.asList(keywords)));
assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs)));
assertFalse(modelManager.equals(new ModelManager(addressBook, new PropertyBook(), userPrefs)));

// resets modelManager to initial state for upcoming tests
modelManager.updateFilteredCustomerList(PREDICATE_SHOW_ALL_CUSTOMERS);

// different userPrefs -> returns false
UserPrefs differentUserPrefs = new UserPrefs();
differentUserPrefs.setAddressBookFilePath(Paths.get("differentFilePath"));
assertFalse(modelManager.equals(new ModelManager(addressBook, differentUserPrefs)));
assertFalse(modelManager.equals(new ModelManager(addressBook, new PropertyBook(), differentUserPrefs)));
}
}
Loading

0 comments on commit 15e526b

Please sign in to comment.