Skip to content

Commit 02c2bf6

Browse files
author
AmiyahJo
committed
feat: adds moneyOrderTest
1 parent e189f72 commit 02c2bf6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class MoneyOrderTest {
10+
11+
private CheckingAccount sourceAccount;
12+
private AuditLog auditLog;
13+
14+
@BeforeEach
15+
public void setup() {
16+
// Arrange
17+
sourceAccount = new CheckingAccount("12345678", "John Doe", true, 1000.0);
18+
auditLog = new AuditLog();
19+
}
20+
21+
@Test
22+
public void testMoneyOrderWithdrawal() {
23+
// Act
24+
MoneyOrder moneyOrder = new MoneyOrder(sourceAccount, 500.0, auditLog);
25+
26+
// Assert
27+
assertEquals(500.0, sourceAccount.getBalance(), "Balance after money order should be 500");
28+
29+
// Assert
30+
assertEquals(1, auditLog.getLogEntries().size(), "Audit log should contain 1 entry");
31+
String logEntry = auditLog.getLogEntries().get(0);
32+
33+
assertTrue(logEntry.contains("Account: 12345678"), "Log should contain the correct account number");
34+
assertTrue(logEntry.contains("MoneyOrder created"), "Log should describe the MoneyOrder creation");
35+
assertTrue(logEntry.contains("-500.00"), "Log should reflect the correct withdrawal amount");
36+
assertTrue(logEntry.contains("MoneyOrder"), "Log should specify the transaction type as 'MoneyOrder'");
37+
}
38+
}

0 commit comments

Comments
 (0)