forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for FilterCustomerDescriptor
- Loading branch information
Showing
5 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/seedu/address/logic/commands/FilterCustomerDescriptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/seedu/address/testutil/FilterCustomerDescriptorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters