forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix In/Out Transactions to take in duplicates. Fix JsonAdaptedTransac…
…tions to read negative amounts
- Loading branch information
Showing
7 changed files
with
247 additions
and
10 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
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
159 changes: 159 additions & 0 deletions
159
src/test/java/seedu/address/logic/commands/UpdateCommandTest.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,159 @@ | ||
package seedu.address.logic.commands; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model, | ||
* UndoCommand and RedoCommand) and unit tests for UpdateCommand. | ||
*/ | ||
public class UpdateCommandTest { | ||
/* | ||
private Model model = new ModelManager(getTypicalBankAccount(), new UserPrefs()); | ||
private String typeTransaction = "t"; | ||
private String typeBudget = "b"; | ||
@Test | ||
public void execute_allFieldsSpecifiedUnfilteredList_success() { | ||
BankAccountOperation editedTransaction = new TransactionBuilder().build(); | ||
UpdateTransactionDescriptor descriptor = new UpdateTransactionDescriptorBuilder(editedTransaction).build(); | ||
UpdateCommand updateCommand = new UpdateCommand(typeTransaction ,INDEX_FIRST_TRANSACTION, descriptor); | ||
String expectedMessage = String.format(UpdateCommand.MESSAGE_UPDATE_TRANSACTION_SUCCESS, editedTransaction); | ||
Model expectedModel = new ModelManager(new BankAccount(model.getBankAccount()), new UserPrefs()); | ||
BankAccountOperation txn = model.getFilteredTransactionList().get(0); | ||
expectedModel.setTransaction(txn, editedTransaction); | ||
assertCommandSuccess(updateCommand, model, expectedMessage, expectedModel); | ||
} | ||
@Test | ||
public void execute_someFieldsSpecifiedUnfilteredList_success() { | ||
Index indexLastTransaction = Index.fromOneBased(model.getFilteredTransactionList().size()); | ||
Transaction lastTransaction = model.getFilteredTransactionList().get(indexLastTransaction.getZeroBased()); | ||
TransactionBuilder transactionInList = new TransactionBuilder(lastTransaction); | ||
// TODO : FIX | ||
Transaction editedTransaction = transactionInList.withAmount("1").withDate("1") | ||
.withCategories(VALID_TAG_HUSBAND).build(); | ||
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB) | ||
.withPhone(VALID_PHONE_BOB).withCategories(VALID_TAG_HUSBAND).build(); | ||
EditCommand editCommand = new EditCommand(indexLastTransaction, descriptor); | ||
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedTransaction); | ||
Model expectedModel = new ModelManager(new BankAccount(model.getBankAccount()), new UserPrefs()); | ||
expectedModel.setTransaction(lastTransaction, editedTransaction); | ||
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); | ||
} | ||
@Test | ||
public void execute_noFieldSpecifiedUnfilteredList_success() { | ||
EditCommand editCommand = new EditCommand(INDEX_FIRST_TRANSACTION, new EditPersonDescriptor()); | ||
Transaction editedTransaction = model.getFilteredTransactionList().get(INDEX_FIRST_TRANSACTION.getZeroBased()); | ||
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedTransaction); | ||
Model expectedModel = new ModelManager(new BankAccount(model.getBankAccount()), new UserPrefs()); | ||
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); | ||
} | ||
@Test | ||
public void execute_filteredList_success() { | ||
showPersonAtIndex(model, INDEX_FIRST_TRANSACTION); | ||
Transaction transactionInFilteredList = model | ||
.getFilteredTransactionList() | ||
.get(INDEX_FIRST_TRANSACTION.getZeroBased()); | ||
// TODO: FIX | ||
Transaction editedTransaction = new TransactionBuilder(transactionInFilteredList).withAmount("1").build(); | ||
EditCommand editCommand = new EditCommand(INDEX_FIRST_TRANSACTION, | ||
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); | ||
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedTransaction); | ||
Model expectedModel = new ModelManager(new BankAccount(model.getBankAccount()), new UserPrefs()); | ||
expectedModel.setTransaction(model.getFilteredTransactionList().get(0), editedTransaction); | ||
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); | ||
} | ||
@Test | ||
public void execute_duplicateTransactionUnfilteredList_failure() { | ||
Transaction firstTransaction = model.getFilteredTransactionList().get(INDEX_FIRST_TRANSACTION.getZeroBased()); | ||
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstTransaction).build(); | ||
EditCommand editCommand = new EditCommand(INDEX_SECOND_TRANSACTION, descriptor); | ||
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); | ||
} | ||
@Test | ||
public void execute_duplicateTransactionFilteredList_failure() { | ||
showPersonAtIndex(model, INDEX_FIRST_TRANSACTION); | ||
// edit person in filtered list into a duplicate in address book | ||
Transaction transactionInList = model | ||
.getBankAccount().getTransactionHistory().get(INDEX_SECOND_TRANSACTION.getZeroBased()); | ||
EditCommand editCommand = new EditCommand(INDEX_FIRST_TRANSACTION, | ||
new EditPersonDescriptorBuilder(transactionInList).build()); | ||
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); | ||
} | ||
@Test | ||
public void execute_invalidTransactionIndexUnfilteredList_failure() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredTransactionList().size() + 1); | ||
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); | ||
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor); | ||
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
/** | ||
* Edit filtered list where index is larger than size of filtered list, | ||
* but smaller than size of address book | ||
*/ | ||
/* | ||
@Test | ||
public void execute_invalidTransactionIndexFilteredList_failure() { | ||
showPersonAtIndex(model, INDEX_FIRST_TRANSACTION); | ||
Index outOfBoundIndex = INDEX_SECOND_TRANSACTION; | ||
// ensures that outOfBoundIndex is still in bounds of address book list | ||
assertTrue(outOfBoundIndex.getZeroBased() < model.getBankAccount().getTransactionHistory().size()); | ||
EditCommand editCommand = new EditCommand(outOfBoundIndex, | ||
new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); | ||
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
@Test | ||
public void equals() { | ||
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_TRANSACTION, DESC_AMY); | ||
// same values -> returns true | ||
EditPersonDescriptor copyDescriptor = new EditPersonDescriptor(DESC_AMY); | ||
EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_TRANSACTION, copyDescriptor); | ||
assertTrue(standardCommand.equals(commandWithSameValues)); | ||
// same object -> returns true | ||
assertTrue(standardCommand.equals(standardCommand)); | ||
// null -> returns false | ||
assertFalse(standardCommand.equals(null)); | ||
// different types -> returns false | ||
assertFalse(standardCommand.equals(new ClearCommand())); | ||
// different index -> returns false | ||
assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_TRANSACTION, DESC_AMY))); | ||
// different descriptor -> returns false | ||
assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_TRANSACTION, DESC_BOB))); | ||
} | ||
*/ | ||
|
||
} |
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
69 changes: 69 additions & 0 deletions
69
src/test/java/seedu/address/testutil/UpdateTransactionDescriptorBuilder.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,69 @@ | ||
package seedu.address.testutil; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.UpdateCommand.UpdateTransactionDescriptor; | ||
import seedu.address.model.category.Category; | ||
import seedu.address.model.transaction.Amount; | ||
import seedu.address.model.transaction.BankAccountOperation; | ||
import seedu.address.model.util.Date; | ||
|
||
/** | ||
* A utility class to help with building UpdateTransactionDescriptor objects. | ||
*/ | ||
public class UpdateTransactionDescriptorBuilder { | ||
|
||
private UpdateTransactionDescriptor descriptor; | ||
|
||
public UpdateTransactionDescriptorBuilder() { | ||
descriptor = new UpdateTransactionDescriptor(); | ||
} | ||
|
||
public UpdateTransactionDescriptorBuilder(UpdateTransactionDescriptor descriptor) { | ||
this.descriptor = new UpdateTransactionDescriptor(descriptor); | ||
} | ||
|
||
/** | ||
* Returns an {@code UpdateTransactionDescriptor} with fields containing | ||
* {@code BankAccountOperation}'s details | ||
*/ | ||
public UpdateTransactionDescriptorBuilder(BankAccountOperation transaction) { | ||
descriptor = new UpdateTransactionDescriptor(); | ||
descriptor.setAmount(transaction.getAmount()); | ||
descriptor.setDate(transaction.getDate()); | ||
descriptor.setCategories(transaction.getCategories()); | ||
} | ||
|
||
/** | ||
* Sets the {@code Amount} of the {@code UpdateTransactionDescriptor} that we are building. | ||
*/ | ||
public UpdateTransactionDescriptorBuilder withAmount(String amount) { | ||
descriptor.setAmount(new Amount(Double.parseDouble(amount))); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code Date} of the {@code UpdateTransactionDescriptor} that we are building. | ||
*/ | ||
public UpdateTransactionDescriptorBuilder withDate(String date) { | ||
descriptor.setDate(new Date(date)); | ||
return this; | ||
} | ||
|
||
/** | ||
* Parses the {@code categories} into a {@code Set<Category>} and set it to the {@code UpdateTransactionDescriptor} | ||
* that we are building. | ||
*/ | ||
public UpdateTransactionDescriptorBuilder withCategories(String... categories) { | ||
Set<Category> categorySet = Stream.of(categories).map(Category::new).collect(Collectors.toSet()); | ||
descriptor.setCategories(categorySet); | ||
return this; | ||
} | ||
|
||
public UpdateTransactionDescriptor build() { | ||
return descriptor; | ||
} | ||
|
||
} |