Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: JUnit test for Transaction class #15

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/test/java/seedu/duke/DukeTest.java

This file was deleted.

52 changes: 52 additions & 0 deletions src/test/java/transactions/TransactionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package transactions;

import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TransactionTest {
@Test
public void testTransactionConstructor() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
assertEquals("Groceries", transaction.getDescription());
assertEquals(50.0f, transaction.getAmount(), 0.001);
assertEquals("Food", transaction.getCategory());
LocalDate date = LocalDate.parse("14-03-2024", DateTimeFormatter.ofPattern("dd-MM-yyyy"));
assertEquals(date, transaction.getDate());
}

@Test
public void testGetDescription() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
assertEquals("Groceries", transaction.getDescription());
}

@Test
public void testGetAmount() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
assertEquals(50.0f, transaction.getAmount(), 0.001);
}

@Test
public void testGetCategory() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
assertEquals("Food", transaction.getCategory());
}

@Test
public void testGetDate() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
LocalDate date = LocalDate.parse("14-03-2024", DateTimeFormatter.ofPattern("dd-MM-yyyy"));
assertEquals(date, transaction.getDate());
}

@Test
public void testToString() {
Transaction transaction = new Transaction("Groceries", 50.0f, "Food", "14-03-2024");
String expected = " Description: Groceries | Date: 2024-03-14 | Amount: 50.0 | Category: Food";
assertEquals(expected, transaction.toString());
}
}
Loading