Skip to content

Commit

Permalink
Add unit test for FilterCustomerDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
FerdiHS committed Oct 31, 2023
1 parent 4140927 commit c0b346b
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.EditCustomerCommand.EditCustomerDescriptor;
import seedu.address.logic.commands.FilterCustomerCommand.FilterCustomerDescriptor;
import seedu.address.logic.commands.FilterPropertyCommand.FilterPropertyDescriptor;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.customer.Customer;
import seedu.address.model.customer.NameContainsKeywordsPredicate;
import seedu.address.testutil.EditCustomerDescriptorBuilder;
import seedu.address.testutil.FilterCustomerDescriptorBuilder;
import seedu.address.testutil.FilterPropertyDescriptorBuilder;

/**
Expand Down Expand Up @@ -62,8 +65,10 @@ public class CommandTestUtil {
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final EditCustomerCommand.EditCustomerDescriptor DESC_AMY;
public static final EditCustomerCommand.EditCustomerDescriptor DESC_BOB;
public static final EditCustomerDescriptor DESC_AMY;
public static final EditCustomerDescriptor DESC_BOB;
public static final FilterCustomerDescriptor FILTER_CUSTOMER_DESCRIPTOR_AMY;
public static final FilterCustomerDescriptor FILTER_CUSTOMER_DESCRIPTOR_BOB;

static {
DESC_AMY = new EditCustomerDescriptorBuilder().withName(VALID_NAME_AMY)
Expand All @@ -72,6 +77,10 @@ public class CommandTestUtil {
DESC_BOB = new EditCustomerDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withBudget(VALID_BUDGET_BOB)
.withTags(VALID_TAG_BIG, VALID_TAG_SQUARE).build();
FILTER_CUSTOMER_DESCRIPTOR_AMY = new FilterCustomerDescriptorBuilder().withBudget(VALID_BUDGET_AMY)
.withTags(VALID_TAG_SQUARE).build();
FILTER_CUSTOMER_DESCRIPTOR_BOB = new FilterCustomerDescriptorBuilder().withBudget(VALID_BUDGET_BOB)
.withTags(VALID_TAG_BIG, VALID_TAG_SQUARE).build();
}

// Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ public void execute_withBudgetSomeTags_customerFound() {
assertEquals(Arrays.asList(BENSON), model.getFilteredCustomerList());
}

@Test
public void toStringMethod() {
String firstTagString = "square";
String secondTagString = "garden";

Tag firstTag = new Tag(firstTagString);
Tag secondTag = new Tag(secondTagString);

Set<Tag> tags = new HashSet<>();
tags.add(firstTag);
tags.add(secondTag);

String budgetString = "100000000";
Budget budget = new Budget(budgetString);

BudgetAndTagsInRangePredicate predicate = new BudgetAndTagsInRangePredicate(budget, tags);
FilterCustomerCommand filterCustomerCommand = new FilterCustomerCommand(predicate);
String expected = FilterCustomerCommand.class.getCanonicalName() + "{predicate=" + predicate + "}";
assertEquals(expected, filterCustomerCommand.toString());
}

private FilterCustomerCommand preparePredicate(String message) {
try {
return (new FilterCustomerCommandParser()).parse(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.FILTER_CUSTOMER_DESCRIPTOR_AMY;
import static seedu.address.logic.commands.CommandTestUtil.FILTER_CUSTOMER_DESCRIPTOR_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_BUDGET_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_BIG;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.FilterCustomerCommand.FilterCustomerDescriptor;
import seedu.address.testutil.FilterCustomerDescriptorBuilder;

public class FilterCustomerDescriptorTest {
@Test
public void equals() {
// same values -> returns true
FilterCustomerDescriptor descriptorWithSameValues =
new FilterCustomerDescriptor(FILTER_CUSTOMER_DESCRIPTOR_AMY);
assertTrue(FILTER_CUSTOMER_DESCRIPTOR_AMY.equals(descriptorWithSameValues));

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

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

// different types -> returns false
assertFalse(FILTER_CUSTOMER_DESCRIPTOR_AMY.equals(5));

// different values -> returns false
assertFalse(FILTER_CUSTOMER_DESCRIPTOR_AMY.equals(FILTER_CUSTOMER_DESCRIPTOR_BOB));

// different price -> returns false
FilterCustomerDescriptor editedAmy = new FilterCustomerDescriptorBuilder(FILTER_CUSTOMER_DESCRIPTOR_AMY)
.withBudget(VALID_BUDGET_BOB).build();
assertFalse(FILTER_CUSTOMER_DESCRIPTOR_AMY.equals(editedAmy));

// different tags -> returns false
editedAmy = new FilterCustomerDescriptorBuilder(FILTER_CUSTOMER_DESCRIPTOR_AMY)
.withTags(VALID_TAG_BIG).build();
assertFalse(FILTER_CUSTOMER_DESCRIPTOR_AMY.equals(editedAmy));
}

@Test
public void toStringMethod() {
FilterCustomerDescriptor filterPropertyDescriptor = new FilterCustomerDescriptor();
String expected = FilterCustomerDescriptor.class.getCanonicalName() + "{budget="
+ filterPropertyDescriptor.getBudget().orElse(null) + ", tags="
+ filterPropertyDescriptor.getTags().orElse(null) + "}";
assertEquals(expected, filterPropertyDescriptor.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.testutil;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import seedu.address.logic.commands.FilterCustomerCommand.FilterCustomerDescriptor;
import seedu.address.model.customer.Budget;
import seedu.address.model.customer.Customer;
import seedu.address.model.tag.Tag;

/**
* A utility class to help with building FilterCustomerDescriptor objects.
*/
public class FilterCustomerDescriptorBuilder {

private FilterCustomerDescriptor descriptor;

public FilterCustomerDescriptorBuilder() {
descriptor = new FilterCustomerDescriptor();
}

public FilterCustomerDescriptorBuilder(FilterCustomerDescriptor descriptor) {
this.descriptor = new FilterCustomerDescriptor(descriptor);
}

/**
* Returns an {@code FilterCustomerDescriptorBuilder} with fields containing {@code customer}'s details
*/
public FilterCustomerDescriptorBuilder(Customer customer) {
descriptor.setBudget(customer.getBudget());
descriptor.setTags(customer.getTags());
}

/**
* Sets the {@code Budget} of the {@code EditCustomerDescriptor} that we are building.
*/
public FilterCustomerDescriptorBuilder withBudget(String budget) {
descriptor.setBudget(new Budget(budget));
return this;
}

/**
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code EditCustomerDescriptor}
* that we are building.
*/
public FilterCustomerDescriptorBuilder withTags(String... tags) {
Set<Tag> tagSet = Stream.of(tags).map(Tag::new).collect(Collectors.toSet());
descriptor.setTags(tagSet);
return this;
}

public FilterCustomerDescriptor build() {
return descriptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public FilterPropertyDescriptorBuilder(Property property) {
}

/**
* Sets the {@code Price} of the {@code EditpropertyDescriptor} that we are building.
* Sets the {@code Price} of the {@code EditPropertyDescriptor} that we are building.
*/
public FilterPropertyDescriptorBuilder withPrice(String price) {
descriptor.setPrice(new Price(price));
return this;
}

/**
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code EditpropertyDescriptor}
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code EditPropertyDescriptor}
* that we are building.
*/
public FilterPropertyDescriptorBuilder withTags(String... tags) {
Expand Down

0 comments on commit c0b346b

Please sign in to comment.