-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and update test cases for testing critical functions in Transacti…
…on and TransactionList
- Loading branch information
Showing
2 changed files
with
157 additions
and
19 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
55 changes: 36 additions & 19 deletions
55
src/test/java/seedu/duke/data/transaction/TransactionTest.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 |
---|---|---|
@@ -1,54 +1,71 @@ | ||
package seedu.duke.data.transaction; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.duke.data.TransactionList; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class TransactionTest { | ||
//@@author chydarren | ||
LocalDate date = LocalDate.of(2022, 1, 1); | ||
Transaction transaction = new Income("Milked cows in the farm", 50, | ||
"Salary", date); | ||
|
||
@Test | ||
public void testGetDescription() { | ||
assertEquals("Milked cows in the farm", transaction.getDescription()); | ||
public void setDescription_setValidDescription_expectSuccessfulSetDescription() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
transaction.setDescription("Milked_cows_in_the_pantry"); | ||
assertEquals("Milked_cows_in_the_pantry", transaction.getDescription()); | ||
} | ||
|
||
@Test | ||
public void testSetDescription() { | ||
transaction.setDescription("Helped the cows to wash their ass"); | ||
assertEquals("Helped the cows to wash their ass", transaction.getDescription()); | ||
public void setAmount_setValidAmount_expectSuccessfulSetAmount() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
transaction.setAmount(500); | ||
assertEquals(500, transaction.getAmount()); | ||
} | ||
|
||
@Test | ||
public void testGetAmount() { | ||
assertEquals(50, transaction.getAmount()); | ||
public void setCategory_setValidCategory_expectSuccessfulSetCategory() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
transaction.setCategory("Chore"); | ||
assertEquals("Chore", transaction.getCategory()); | ||
} | ||
|
||
@Test | ||
public void testSetAmount() { | ||
transaction.setAmount(500); | ||
assertEquals(500, transaction.getAmount()); | ||
public void setDate_setValidDate_expectSuccessfulSetDate() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
transaction.setDate(LocalDate.of(2022, 10, 30)); | ||
assertEquals(transaction.getDate(), LocalDate.of(2022, 10, 30)); | ||
} | ||
|
||
@Test | ||
public void testGetCategory() { | ||
assertEquals("Salary", transaction.getCategory()); | ||
public void compareTo_inputTransactionWithEarlierDate_expectTransactionSortAsEarlier() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
Transaction earlierTransaction = new Expense("Bought_cow_food", 50, | ||
"Food", LocalDate.of(2021, 12, 25)); | ||
assertTrue(transaction.compareTo(earlierTransaction) > 0); | ||
} | ||
|
||
@Test | ||
public void testSetCategory() { | ||
transaction.setCategory("Love"); | ||
assertEquals("Love", transaction.getCategory()); | ||
public void compareTo_inputTransactionWithLaterDate_expectTransactionSortAsLater() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
Transaction laterTransaction = new Expense("Destroy_the_farm", 1000, | ||
"Food", LocalDate.of(2022, 9, 20)); | ||
assertTrue(transaction.compareTo(laterTransaction) < 0); | ||
} | ||
|
||
//@@author wcwy | ||
|
||
@Test | ||
public void printFormattedDate_validDateFormat_expectCorrectFormatDate() { | ||
Transaction transaction = new Income("Milked_cows_in_the_farm", 50, | ||
"Salary", LocalDate.of(2022, 1, 1)); | ||
assertEquals(transaction.printFormattedDate(), "Jan 01 2022"); | ||
} | ||
} |