forked from AY2324S2-CS2103-F15-2/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.
- Loading branch information
1 parent
36ada51
commit fc655bc
Showing
4 changed files
with
191 additions
and
1 deletion.
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
97 changes: 97 additions & 0 deletions
97
src/test/java/seedu/address/logic/commands/PaymentCommandTest.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,97 @@ | ||
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.assertCommandSuccess; | ||
import static seedu.address.logic.commands.FilterCommand.MESSAGE_FILTER_ADDRESS_BOOK_SUCCESS; | ||
import static seedu.address.testutil.TypicalPersons.ALICE; | ||
import static seedu.address.testutil.TypicalPersons.BENSON; | ||
import static seedu.address.testutil.TypicalPersons.CARL; | ||
import static seedu.address.testutil.TypicalPersons.DANIEL; | ||
import static seedu.address.testutil.TypicalPersons.ELLE; | ||
import static seedu.address.testutil.TypicalPersons.FIONA; | ||
import static seedu.address.testutil.TypicalPersons.GEORGE; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.Messages; | ||
import seedu.address.model.CommandHistory; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.*; | ||
|
||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code PaymentCommand}. | ||
*/ | ||
public class PaymentCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), new CommandHistory()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), new CommandHistory()); | ||
|
||
@Test | ||
public void equals() { | ||
PaymentFilterPredicate firstPredicate = | ||
new PaymentFilterPredicate(new Payment()); | ||
PaymentFilterPredicate secondPredicate = | ||
new PaymentFilterPredicate(new Payment("Paid")); | ||
|
||
PaymentCommand PaymentFirstCommand = new PaymentCommand(firstPredicate); | ||
PaymentCommand PaymentSecondCommand = new PaymentCommand(secondPredicate); | ||
|
||
// same object -> returns true | ||
assertTrue(PaymentFirstCommand.equals(PaymentFirstCommand)); | ||
|
||
// same values -> returns true | ||
PaymentCommand findFirstCommandCopy = new PaymentCommand(firstPredicate); | ||
assertTrue(PaymentFirstCommand.equals(findFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(PaymentFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(PaymentFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(PaymentFirstCommand.equals(PaymentSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void execute_filterPayment_noStudentFound() { | ||
PaymentFilterPredicate predicate = | ||
new PaymentFilterPredicate(new Payment("Not Paid")); | ||
String expectedMessage = | ||
String.format(MESSAGE_FILTER_ADDRESS_BOOK_SUCCESS + Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, | ||
0, predicate.filterResult()); | ||
PaymentCommand command = new PaymentCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Collections.emptyList(), model.getFilteredPersonList()); | ||
} | ||
|
||
@Test | ||
public void execute_filterPayment_multipleStudentsFound() { | ||
PaymentFilterPredicate predicate = | ||
new PaymentFilterPredicate(new Payment("Paid")); | ||
String expectedMessage = | ||
String.format(MESSAGE_FILTER_ADDRESS_BOOK_SUCCESS + Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, | ||
7, predicate.filterResult()); | ||
PaymentCommand command = new PaymentCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE), model.getFilteredPersonList()); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
PaymentFilterPredicate predicate = new PaymentFilterPredicate(new Payment()); | ||
PaymentCommand filterCommand = new PaymentCommand(predicate); | ||
String expected = PaymentCommand.class.getSimpleName() + "{predicate=" + predicate + "}"; | ||
assertEquals(expected, filterCommand.toString()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/seedu/address/logic/parser/PaymentCommandParserTest.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,35 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.PaymentCommand; | ||
import seedu.address.model.person.Payment; | ||
import seedu.address.model.person.PaymentFilterPredicate; | ||
|
||
|
||
public class PaymentCommandParserTest { | ||
|
||
private PaymentCommandParser parser = new PaymentCommandParser(); | ||
|
||
@Test | ||
public void parse_emptyArg_throwsParseException() { | ||
assertParseFailure(parser, " ", | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, PaymentCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_validArgs_returnsFilterCommand() { | ||
// no trailing whitespaces | ||
PaymentCommand expectedPaymentCommand = | ||
new PaymentCommand(new PaymentFilterPredicate(new Payment("Paid"))); | ||
assertParseSuccess(parser, " pa/paid", expectedPaymentCommand); | ||
|
||
// multiple whitespaces between keywords | ||
assertParseSuccess(parser, " \n pa/ \n \t paid \t", expectedPaymentCommand); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/seedu/address/model/person/PaymentPredicateTest.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,58 @@ | ||
package seedu.address.model.person; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class PaymentPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
PaymentFilterPredicate firstPredicate = new PaymentFilterPredicate( | ||
new Payment()); | ||
|
||
PaymentFilterPredicate secondPredicate = new PaymentFilterPredicate( | ||
new Payment("Paid")); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
PaymentFilterPredicate firstPredicateCopy = new PaymentFilterPredicate( | ||
new Payment()); | ||
assertTrue(firstPredicate.equals(firstPredicateCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// different filter -> returns false | ||
assertFalse(firstPredicate.equals(secondPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_filterContainsPayment_returnsTrue() { | ||
PaymentFilterPredicate predicate = new PaymentFilterPredicate(new Payment("Paid")); | ||
assertTrue(predicate.test(new PersonBuilder().withName("Alice Bob").build())); | ||
} | ||
|
||
@Test | ||
public void test_filterContainsGradeSubject_returnsFalse() { | ||
PaymentFilterPredicate predicate = new PaymentFilterPredicate( | ||
new Payment("Not Paid")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Alice").build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
String payment = "Paid"; | ||
PaymentFilterPredicate predicate = new PaymentFilterPredicate( | ||
new Payment(payment)); | ||
|
||
String expected = PaymentFilterPredicate.class.getSimpleName() + "{Payment=" + payment + "}"; | ||
assertEquals(expected, predicate.toString()); | ||
} | ||
} |